#3: 1 + '2' + 3
Topic: coercion · Difficulty: ★
console.log(1 + '2' + 3);Output
123
Why
The + operator is evaluated left to right, and the moment one operand is a string, + means concatenation. 1 + '2' hits that rule: the number 1 is converted to '1' and glued to '2', giving the string '12'. Then '12' + 3 converts 3 to '3' and produces '123'. Every other arithmetic operator (-, *, /) would instead convert the string to a number — '2' - 1 is 1 — which is why + is the operator that surprises people.
More coercion puzzles