0

On Mozilla Org's website, the polyfill code of Array.prototype.some has this line:

var len = t.length >>> 0;

What is this line for, as opposed to just

var len = t.length;

?

nonopolarity
  • 146,324
  • 131
  • 460
  • 740
  • 5
    [What does x >>> 0 do?](//stackoverflow.com/q/4081216) and [What is the JavaScript >>> operator and how do you use it?](//stackoverflow.com/q/1822350) – Tushar Apr 24 '17 at 11:26
  • Type coercion, I guess. `undefined >>> 0` is `0` – Thilo Apr 24 '17 at 11:27
  • @Tushar so it basically forces `t.length` to be whatever it's actual value is to be an integer or if unable to convert to an integer it will set `len` to be `0` – George Apr 24 '17 at 11:29
  • the answer in the other question says, "to make sure it is positive (or non-negative)"... oh but `t.length` is always non-negative, so why still do the `>>> 0` ? – nonopolarity Apr 24 '17 at 11:35

0 Answers0