Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Javascript, what is the effect of '>>> 0' on a variable? [duplicate]

Tags:

javascript

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?

like image 461
Andrew Shepherd Avatar asked May 29 '15 03:05

Andrew Shepherd


1 Answers

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.

like image 118
Arun Prasath Avatar answered Oct 09 '22 22:10

Arun Prasath