What is ">>>" operator in JS? [duplicate] What is ">>>" operator in JS? [duplicate] arrays arrays

What is ">>>" operator in JS? [duplicate]


>>> 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.


It's a zero-fill right shift. When you bit-shift a number, you can either decide to fill the left-most bits with zeros or with the sign bit.

In a two's complement number representation, negative numbers have a 1 as the leading bit whereas positive numbers have a 0. Thus if you don't "sign extend" (filling with zeros instead) and shift a negative number, it will result in a positive number.