Favorites

JavaScript isNaN() Function

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
isNaN()
JavaScript Global functionThis function is supported by all modern browsers.
Updated 28th November 2026

The isNaN() function checks whether a value is NaN after converting it to a number. Number.isNaN() is usually the better choice.

Description

The global isNaN() function returns true if the value is NaN after being converted to a number. Because of that conversion, it returns true for values that are not numbers at all, such as 'hello' and undefined. That can be useful for checking user input, but to check whether a value is literally NaN, use Number.isNaN().

The conversion follows the same rules as Number(): empty strings and null become 0, so isNaN('') and isNaN(null) are false, which may not be what you expect when validating input. Checking Number.isNaN(Number(value)) spells out the conversion explicitly.

For validating that a string is a number, also check that it isn't empty, for example value.trim() !== '' && !isNaN(value), or use a regular expression for the exact format you expect.

Syntax

isNaN(value)

Parameters

  • valueThe value to test. It is converted to a number first.

Return Value

true if the value is NaN after conversion to a number, otherwise false.

Example

console.log(isNaN(NaN));
console.log(isNaN('hello'));
console.log(isNaN('42'));
console.log(Number.isNaN('hello'));

Browser Support

The following information will show you the current browser support for the isNaN() function. Hover over a browser icon to see the version that first introduced support for this function.

This function is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee