#22: let x = '5'; x++
Topic: numbers · Difficulty: ★
let x = '5';
x++;
console.log(x);
console.log(typeof x);Output
6 number
Why
The ++ operator is purely numeric — it always converts its operand with ToNumber before incrementing, regardless of the operand's original type. x starts as the string '5', but x++ first coerces it to the number 5, adds 1, and assigns the number 6 back to x. The variable silently changes type from string to number in the process, which is a common source of bugs when a numeric-looking string sneaks in from user input or a form field.