NaN, the not-a-number number that isn't NaN

Developers meltdown: the number that won’t equal itself

TLDR: NaN is a special “error” number in JavaScript that even refuses to equal itself, preventing bad math from hiding. Commenters split between type purists wanting undefined, pragmatists using simple checks, and meme-makers posting “NaNNaNNaN… Batman!”—because understanding this quirk stops real-world bugs.

JavaScript’s weirdest celebrity, NaN (“not a number”), just got a fresh spotlight from Mat “Wilto” Marquis—and the comments lit up like a bug report on Friday at 5pm. The article explains that NaN is a special “error” number used to signal math gone wrong, and it’s famously not equal to itself. That quirky behavior keeps broken math from silently turning into fake results. Think of it as a bright red flag, not a sneaky gremlin. But the crowd? Divided.

On one side, the type-system purists are raging. User andai wants bad comparisons to just be undefined, not false—anything else feels like logic gaslighting. Meanwhile, the pragmatists shrug and say, “Use Number.isFinite() and move on,” with tuyiown flexing the practical fix. Then come the chaos agents: Zealotux drops the legendary “NaNNaNNaN… Batman!” code joke, while kace91 suggests checking if the value turns into the string “NaN,” which sparked a chorus of “please don’t” replies. There’s even a naming crusade: amelius proposes calling it NaVN (“not a valid number”), because if it walks like an error, why pretend it’s a number? Drama, memes, and a surprising amount of math feelings—exactly the way NaN likes it.

Key Points

  • Any arithmetic expression involving NaN evaluates to NaN in JavaScript.
  • All comparisons with NaN (>, <, ==, ===) evaluate to false; NaN !== NaN is true.
  • typeof NaN returns “number,” reflecting NaN’s participation in numeric operations.
  • JavaScript’s NaN behavior follows IEEE 754 rules, which require NaN propagation to signal errors.
  • Because NaN is not equal to itself, equality/inequality checks cannot reliably detect NaN, necessitating special handling.

Hottest takes

"Shouldn’t an operator on incompatible types return undefined? ;)" — andai
"I just use Number.isFinite() when I need a real (haha) number" — tuyiown
"console.log(new Array(16).join(\"wat\"-1) + \" Batman!\")" — Zealotux
Made with <3 by @siedrix and @shesho from CDMX. Powered by Forge&Hive.