kriskowal/es5-shim — Issue #78: question: why `self.length >>> 0`?
Author: millermedeiros
Created: 2011-11-23 15:19:39+00:00
State: open

I've seen a lot of people using `length >>> 0` on their code (including the MDN shims) but never really understood why, just want to clarify the reasoning behing it, I know what `>>>` does just don't understand why it's being used in this case..

if `length` is negative it will return `Math.pow(2, 32) + length` (that's what zero-fill right shift does with negative numbers..) if length is `NaN` it will return `0` and if value is positive it will do a `Math.floor()` (because bitwise operations works with integers..)

why not simply do `~~length`?? it will take care of `NaN` and `Math.floor()` and negative lengths will be ignored since loops won't execute..

```js
~~ 0.35; // 0
~~ 9.75; // 9
~~ -9.75; // -9
~~ ''; // 0
~~ 'foo'; // 0
~~ NaN; // 0
```

in the current setup if `self.length` is negative (probably won't happen :P) it will cause an "infinite" loop.