>> 0" on a variable? I read the implementation of Array.prototype.some on developer.mozilla.org It contai...">

In Javascript, what is the effect of ">>> 0" on a variable?

I read the implementation of Array.prototype.some on developer.mozilla.org

It contains this inlaid piece of code:

 var t = Object(this); var len = t.length >>> 0; for (var i = 0; i < len; i++) { 

Why does it call len = t.length >>> 0 instead of len = t.length ?

What is the difference >>> 0 ?

+5
source share
1 answer

performs a logical (unsigned) right shift of 0 bits, which is equivalent to no-op. However, before shifting to the right, it must convert x to an unsigned 32-bit integer. Thus, the overall effect x โ†’> 0 converts x to an unsigned 32-bit integer.

+7
source

All Articles