Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
63
rated 0 times [  64] [ 1]  / answers: 1 / hits: 20657  / 12 Years ago, mon, april 30, 2012, 12:00:00

Possible Duplicate:

javascript >>> operator?

JavaScript triple greater than






Found this operator in such line of code:



var t = Object(this),
len = t.length >>> 0;


What does this operator mean?



Full code is below. It is the code of JS some method:



if (!Array.prototype.some) {
Array.prototype.some = function(fun /*, thisp */) {
use strict;

if (this == null) throw new TypeError();

var t = Object(this),
len = t.length >>> 0;

if (typeof fun != function) throw new TypeError();

var thisp = arguments[1];

for (var i = 0; i < len; i++) {
if (i in t && fun.call(thisp, t[i], i, t))
return true;
}

return false;
};
}

More From » arrays

 Answers
115

>>> is a right shift without sign extension



If you use the >> operator on a negative number, the result will also be negative because the original sign bit is copied into all of the new bits. With >>> a zero will be copied in instead.



In this particular case it's just being used as a way to restrict the length field to an unsigned 31 bit integer, or in other words to cast Javascript's native IEEE754 double number into an integer.


[#85887] Saturday, April 28, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
andreguym

Total Points: 125
Total Questions: 112
Total Answers: 103

Location: Wallis and Futuna
Member since Tue, Mar 30, 2021
3 Years ago
;