Skip to content

NaN

Not a Number

Easy — everyone uses thisGeneral Dev

ELI5 — The Vibe Check

NaN means 'Not a Number' — it is what JavaScript gives you when math goes wrong in a weird way. Try to parse a word as a number and you get NaN. The bizarre thing: NaN is technically of type 'number' and does not equal itself. It is JavaScript's way of saying 'this math made no sense'.

Real Talk

NaN is a special numeric value defined by the IEEE 754 floating-point standard representing an undefined or unrepresentable mathematical result. In JavaScript, NaN arises from invalid number operations (parsing non-numeric strings, dividing 0/0, Math.sqrt(-1)). Crucially, NaN !== NaN by specification — use Number.isNaN() to check for it, not strict equality.

Show Me The Code

// How NaN appears:
console.log(parseInt('hello'));    // NaN
console.log(0 / 0);               // NaN
console.log(Math.sqrt(-1));       // NaN
console.log(undefined + 1);       // NaN

// The weird part:
console.log(NaN === NaN);         // false! NaN never equals itself

// Correct way to check:
console.log(Number.isNaN(NaN));   // true
console.log(isNaN('hello'));      // true (coerces first — beware)
console.log(Number.isNaN('hello')); // false (strict, no coercion)

When You'll Hear This

"The calculation returns NaN — you're probably parsing a string as a number." / "Use Number.isNaN(), not isNaN() — they behave differently."

Made with passive-aggressive love by manoga.digital. Powered by Claude.