isNaN()
The global isNaN() function converts its argument to a number and returns true when the result is NaN, or false otherwise. Because of that conversion, a string that doesn’t read as a number counts as NaN too:
> isNaN("hello")
true
> isNaN("42")
false
> isNaN(NaN)
true
isNaN() is an ECMAScript built-in. The static method Number.isNaN() is a separate function that skips the conversion, so Number.isNaN("hello") returns false.
Syntax
The isNaN() function takes a single argument:
isNaN(<value>)
| Parameter | Description |
|---|---|
value |
The value to test. Any value that isn’t a number is converted to one first, with the same rules as the unary plus operator, +value |
The function isn’t a constructor, so calling it with new throws a TypeError.
Return Value
The result is a boolean: true when the converted value is NaN, and false for every other number, including Infinity.
The conversion runs before the check, so it can throw. A bigint or a symbol argument throws a TypeError, because neither converts to a number. An object’s [Symbol.toPrimitive](), .valueOf(), or .toString() method runs during the conversion, and any error it throws propagates.
Examples
A booking form reads a guest count from a text field, where the value is always a string. Converting the input lets the form reject text that isn’t a number:
> isNaN("3")
false
> isNaN("three")
true
> isNaN("3 guests")
true
A scheduling app builds a Date from user input and needs to know whether the date is valid. An invalid date converts to NaN, so isNaN() detects it without reading the time value first:
> isNaN(new Date("2026-11-14"))
false
> isNaN(new Date("2026-13-45"))
true
Common Gotchas
Empty and whitespace-only strings, null, and Booleans all convert to real numbers, so isNaN() reports them as numbers. A form check built on isNaN() alone accepts a blank field:
> isNaN("")
false
> isNaN(" ")
false
> isNaN(null)
false
> isNaN(true)
false
A BigInt value can’t be converted to a number, so the call throws instead of returning false:
> isNaN(10n)
Uncaught TypeError: Cannot convert a BigInt value to a number
at isNaN (<anonymous>)
To test whether a value is the NaN number itself, without any conversion, Number.isNaN() returns false for every argument that isn’t a number, including a bigint.
Related Resources
Course
JavaScript Numbers for Pythonistas
Port a coffee roastery's batch planner from Python to JavaScript, and learn to divide, round, read numbers from text, and format them with JavaScript's one number type.
For additional information on related topics, take a look at the following resources:
- Compare and Convert (Course)
Have a question about this? Mentor AI can show you examples, compare related terms, and point you to tutorials.
By Leodanis Pozo Ramos • Updated Nov. 14, 2026