#11: typeof NaN and typeof Infinity
Topic: misc · Difficulty: ★★
console.log(typeof NaN);
console.log(typeof Infinity);Output
number number
Why
NaN literally stands for 'Not a Number', which makes its typeof result feel backwards — but NaN is a specific IEEE-754 floating-point bit pattern, so the language classifies it as a number, just an invalid one. Infinity is the same story: it's a legitimate double-precision float value representing an overflow, not a separate 'infinite' type. Both live in the same numeric type as 1, -3.5, and 0, which is why arithmetic like NaN + 1 or Infinity - 1 doesn't throw — it just produces another number.
More misc puzzles