What Is The Javascript >>> Operator Used For?
What does the JavaScript >>> operator do? For example, alert(1 >>> 2). How do we use it?
Solution 1:
It is a bitwise operator, here is an explanation taken from this page.
This is the zero-fill right shift operator which shifts the binary representation of the first operand to the right by the number of places specified by the second operand. Bits shifted off to the right are discarded and zeroes are added on to the left. With a positive number you would get the same result as with the sign-propagating right shift operator, but negative numbers lose their sign becoming positive as in the next example, which (assuming 'a' to be -13) would return 1073741820:
Watch out though, bitwise operators are pretty slow in JavaScript.
Solution 2:
It's the zero-fill right shift operator (as opposed to the sign-propagating right shift, >>
).
Post a Comment for "What Is The Javascript >>> Operator Used For?"