Series
Why typeof NaN === "number" Even Though It Means "Not a Number"
Understanding one of JavaScript's most confusing behaviors: why NaN is considered a number type.
1 min read
Why typeof NaN === "number"
This is one of JavaScript's most confusing aspects. Let's explore why.
The Typeof Operator
The typeof operator returns the type of a value. For NaN, it returns "number", which seems contradictory.
Historical Reasons
This behavior exists for historical reasons. NaN was designed to be a numeric value that represents "not a number" in mathematical operations.
The Reality
Even though NaN means "Not a Number", it's technically a numeric type in JavaScript. It's a special floating-point value.
Practical Implications
Understanding this helps you write better error handling and type checking code.