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)
?).
This seems to be the safest way to ensure length is a non-negative (32-bit) integer.
Just another example of where JavaScript lacks proper standard functions, this time for save conversion of unknown types into, well, 32-bit unsigned integers.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With