whatstheoutput_

#26: '5' + 3 - 2

Topic: coercion · Difficulty: ★★★

console.log('5' + 3 - 2);
console.log(typeof ('5' + 3 - 2));

Output

51
number

Why

This expression is evaluated left to right, and each operator makes its own independent decision about coercion based only on what it currently sees. First, '5' + 3 runs: because one operand is a string, + means concatenation, producing the string '53'. That result then feeds into - 2, but subtraction has only one meaning — it always converts both sides to numbers — so '53' becomes 53, and 53 - 2 is 51, a genuine number. The lesson: + and - can flip between string and number behavior mid-expression, and only the final operator's type determines the overall type.

More coercion puzzles

Play today's puzzle →