1 + + "1" === 2;
Unary operator +
has higher precedence, so +"1"
will be evaluated first, converting "1"
into integer of value of 1, so it will become
1+1 === 2
The second line
+"1" + + "1" === 2;
This is similar. Unary operator +
has higher precedence, so both +"1"
will be evaluate to positive integer value of 1.
"1" + "1" === "11"
Because in JavaScript +
is also string concatenation operator if both operands are string, this will concat both strings.
More information
https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Operators/Arithmetic_Operators
Update: @torazaburo is correct.