Hacker News new | ask | show | jobs
by l_t 2992 days ago
The JS code in question:

console.log([1,2,3,4,5,6,7] ^ 2);

This produces 2 because ^ is the bitwise XOR operator in Javascript. Arrays are not numeric types, so they appear to be coerced to 0 for this comparison. In short, they are effectively logging "0 XOR 2", which is 2.

1 comments

I think it is actually NaN since it should be equivalent to Number([1,2,3])