0

I came across some code as noted below and am confused as to what it's doing.

hash += (hash << 10);
tkone
  • 19,271
  • 5
  • 50
  • 77
mdgrech
  • 947
  • 1
  • 8
  • 22

2 Answers2

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?

tkone
  • 19,271
  • 5
  • 50
  • 77
0

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.

Justin Ethier
  • 122,367
  • 49
  • 219
  • 273