Possible Duplicates:
1. What good does zero-fill bit-shifting by 0 do? (a >>> 0)
2. JavaScript triple greater than
I was digging through some MooTools code, and noticed this snippet being used in every array method:
var length = this.length >>> 0;
What’s the benefit of doing this? It doesn’t seem to me like it’s some max length thing, as 3247823748372 >>> 0 === 828472596 and 3247823748373 >>> 0 === 828472597 (so, both are 1 higher, if it were for maxLength wouldn’t it be better to do something like var length = Math.min(this.length, MAX_LENGTH)?).
>>>is the bitwise “zero-fill right shift” operator.JavaScript numbers can represent both integers and floating point numbers. Sometimes you only want an integer. Any positive JavaScript Number representing a number less than 2^32 will be rounded down (truncated, as in
Math.floor) to the nearest integer. Numbers ≥ 2^32 are turned to 0. Numbers less than 0 will turn into a positive value (thanks to the magic of two’s-complement representation).However,
this.lengthwould presumably ALWAYS be an integer less than 2^32…so I can’t explain why the code would be doing that. The result should be the same asthis.length.