问题
This question already has an answer here:
- What do these JavaScript bitwise operators do? 3 answers
I came across some code as noted below and am confused as to what it's doing.
hash += (hash << 10);
回答1:
It's a Bitwise Operator.
Here's an example from the MDN (linked to above):
9 (base 10): 00000000000000000000000000001001 (base 2)
--------------------------------
9 << 2 (base 10): 00000000000000000000000000100100 (base 2) = 36 (base 10)
See how the 1s have shifted?
回答2:
This is one of the JavaScript bitwise operators:
Left Shift
a << b
Shifts a in binary representation b (< 32) bits to the left, shifting in zeros from the right.
来源:https://stackoverflow.com/questions/9606050/what-do-the-and-operator-do