JavaScript triple greater than

后端 未结 4 1291
深忆病人
深忆病人 2020-11-27 15:30

I saw this syntax on another StackOverflow post and was curious as to what it does:

var len = this.length >>> 0;

What does >&g

4条回答
  •  半阙折子戏
    2020-11-27 15:57

    >>> is a bit-wise operator, zero-fill right shift.

    I think the only effect of >>> 0 on a positive number is to round down to the nearest integer, same as Math.floor(). I don't see why this would be necessary in your example, as generally a .length property (e.g. of an Array) would be an integer already.

    I've also seen the slightly shorter ~~ used in the same way: ~~9.5 == 9; // true.

提交回复
热议问题