Possible Duplicate:
What good does zero-fill bit-shifting by 0 do? (a >>> 0)
I've been trying out some functional programming concepts in a project of mine and I was reading about Array.prototype.map
, which is new in ES5 and looks like this:
Array.prototype.map = function(fun) {
"use strict";
if (this === void 0 || this === null) {
throw new TypeError();
}
var t = Object(this);
var len = t.length >>> 0;
if (typeof fun !== "function") {
throw new TypeError();
}
var res = new Array(len);
var thisp = arguments[1];
for (var i = 0; i < len; i++) {
if (i in t) {
res[i] = fun.call(thisp, t[i], i, t);
}
}
return res;
};
What I'm wondering is why it's doing t.length >>> 0
. Because it doesn't seem to do anything. x >>> 0 //-> x
! (as long as x is a number, obviously)
Also, note that I don't know how bitwise operators work.