🟑 MediumType CoercionπŸ’» Output Question

NaN comparison

πŸ’‘

Hint

NaN !== NaN. Always use Number.isNaN() not isNaN() β€” isNaN coerces its argument first.

What does this output?

console.log(NaN == NaN);
console.log(NaN === NaN);
console.log(NaN != NaN);
console.log(Number.isNaN(NaN));
console.log(isNaN('hello'));

Correct Output

false
false
true
true
true

Why this output?

Explanation: NaN is the only value not equal to itself (both == and ===). Use Number.isNaN() for reliable check. Legacy isNaN() coerces first β€” isNaN("hello") converts "hello" to NaN then returns true.

Key Insight: NaN !== NaN. Always use Number.isNaN() not isNaN() β€” isNaN coerces its argument first.

More Type Coercion Output Questions

🟒 EasyLoose equality coercionβ†’πŸŸ‘ MediumAddition vs concatenationβ†’πŸŸ‘ MediumFalsy values comparisonβ†’πŸ”΄ HardObject to primitive coercionβ†’

Practice predicting output live β†’

66 output questions with instant feedback

πŸ’» Try Output Quiz