CodePeek
Practice / ValuesBack to CodePeek

JavaScript Numeric coercion: Same string, new operator

Puzzle 2 of 15 · Numeric coercion

Compare subtraction and addition using the same string operand. Predict both console logs while tracking numeric conversion and concatenation. Choose an output below, then check the explanation. No signup needed. Browse puzzles by topic →

Values / Numeric coercionJavaScript
console.log("5" - 2);
console.log("5" + 2);

Predict the console output. Each line is a separate log.

What’s the output?

Choose the output

Starter puzzles 15