Tutorial needed that will tell me what ">>>" means

jackroger

Banned
Jul 15, 2010
10
0
0
Hey


I have a javascript where ">>>", ">>", and "<<" appear in the code. I don't know what these mean. I can't find a tutorial that will explain it to me. Anyone know of one? Or knows what they mean?

thanks
 


Those are left and right shift operators. When there are three of them, it's call an unsigned shift operator.

Left shift is analogous to multiplication by 2. Every place you shift, it's the same as multiplying by 2

Code:
14 << 1 == 28
Right shift is analogous to division by 2

Code:
14 >> 1 == 7
Sometimes you'll see code like in the first function in this tutorial, where they have this line:

Code:
var len = this.length >>> 0;
as opposed to the more familiar coercion

Code:
var len = this.length || 0;
or the more verbose

Code:
var len = this.length ? this.length : 0;
The unsigned right shift is used to ensure that `len` is not just always an integer, but always positive as well.

Google bitwise operators for more.