I am reading an implementation of Array.prototype.some
on developer.mozilla.org
It contains this intruiging piece of code:
var t = Object(this);
var len = t.length >>> 0;
for (var i = 0; i < len; i++) {
Why is it calling len = t.length >>> 0
instead of len = t.length
?
What difference does >>> 0
make?
performs a logical (unsigned) right-shift of 0 bits, which is equivalent to a no-op. However, before the right shift, it must convert the x to an unsigned 32-bit integer. Therefore, the overall effect of x >>> 0 is convert x into a 32-bit unsigned integer.
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