Skip to content

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:

Language: JavaScript
> 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:

Language: JavaScript Syntax
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:

Language: JavaScript
> 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:

Language: JavaScript
> 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:

Language: JavaScript
> 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:

Language: JavaScript
> 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.

A developer pulls a Math.floor() lever on a counting machine with a coffee sack on its scale, a big dial, a % gauge and a toFixed(2) receipt printer.

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.

basics js py

For additional information on related topics, take a look at the following resources:

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