I really think the title explains it thoroughly enough. I stumbled upon this oddity when I used an ampersand instead of a plus sign in some string manipulation code. Found it interesting. Could somebody explain this for me?
I really think the title explains it thoroughly enough. I stumbled upon this oddity
Share
Because all bitwise operators1, including the bitwise and (
&), work with 32-bit integers.This operator will convert the two operands to signed 32-bit integers using the abstract
ToInt32operation 2, and if the value is not a number, the result of this conversion is0.At the end your expression becomes evaluated as:
References:
Binary Bitwise Operators ECMA-262, 3rd. Ed. Section 11.10
ToInt32, ECMA-262, Section 9.5