What does this: >> mean in JavaScript?
Seen in this context:
document.onkeydown = document.onkeyup = function(e,v,y,k) {
(i=e.keyCode-37)>>2 || (keys[i] = e.type[5]&&1||(0))
}
The greater than or equal operator ( >= ) returns true if the left operand is greater than or equal to the right operand, and false otherwise.
$ and $$ are valid variable names in JavaScript, they have no special meaning. Usually they set their value to library instances, in your example if you check the closure call, at the end of the file you'll see that $ is jQuery in this case if it is defined and $$ is cytoscape.
Bitwise operators treat its operands as a set of 32-bit binary digits (zeros and ones) and perform actions. However, the result is shown as a decimal value.
>>
is the bitwise right shift operator.
For example: 4 >> 1
equals 2
because 4 is 100
in binary notation, which is shifted one bit to the right, giving us 10
= 2
Javascript Bitwise Operators
Left shift a << b Shifts a in binary representation b (< 32) bits to the left, shifting in zeros from the right.
Sign-propagating right shift a >> b Shifts a in binary representation b (< 32) bits to the right, discarding bits shifted off.
(i=e.keyCode-37)>>2
This code is discarding the two least significant bits of i (similar to dividing by 4), and comparing the result to zero. This will be false when the key pressed is 37-40 (arrow keys), and true otherwise.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With