What does console.log(+true, +null, +undefined, +'') output?
A past puzzle — fully playable. 4 attempts, hints on wrong guesses.
stdle-65.js
1console.log(+true,+null,+undefined,+'')
Coercion
Answer & explanation
Console output
1 0 NaN 0
Why
The unary + operator runs ToNumber on its operand. true converts to 1, null converts to 0, the empty string converts to 0, but undefined is special and converts to NaN. This makes undefined the odd one out: it is the only one of these four that does not produce a clean finite number.