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.
^ is XOR. The author’s “translation” to JavaScript made inconsistent changes in the notation. Here we’re XOR between 2 and a non numeric value, which is coerced into a Number (NaN I think here), and NaN bitshifted with anything gives that thing.