3 ms·
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,
by l_t 9y 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.
- mattnewton 9y agoI think it is actually NaN since it should be equivalent to Number([1,2,3])