In the case of 1^3
the XOR operator executes some binary data to get 2.
1 = 00000001 ^ 3 = 00000011
JavaScript sees the syntax of the [x,y]
array as NaN
when you start doing math things with it. NaN
interpreted as 0
when you perform bitwise operations on it, so the math foo
and bar
starts to take into account the following:
foo => NaN = 00000000 ^ bar => NaN = 00000000 ======== 00000000 = 0 foo => NaN = 00000000 ^ 3 = 00000011 ======== 00000011 = 3
This seems to be true. [1,2]^7 = 7
, [1,2,3]^9 = 9
, etc.
source share