JavaScript isNaN()

Example

Check if a value is NaN:

isNaN(123);
isNaN(-1.23);
isNaN(5-2);
isNaN(0);
Try it Yourself »
isNaN('123');
isNaN('Hello');
isNaN('2005/12/12');
Try it Yourself »

More examples below.


Description

In JavaScript NaN is short for "Not-a-Number".

The isNaN() method returns true if a value is NaN.

The isNaN() method converts the value to a number before testing it.


Difference Between isnan() and Number.isnan()

isNaN() method returns true if a value is Not-a-Number.

Number.isNaN() returns true if a number is Not-a-Number.

In other words:

isNaN() converts the value to a number before testing it.

Examples

// This returns true;
isNaN('Hello');
Try it Yourself »
// This returns false;
Number.isNaN('Hello');
Try it Yourself »

Syntax

isNaN(value)

Parameters

Parameter Description
value Required.
The value to be tested.

Return Value

Type Description
A booleantrue if the value is NaN, otherwise false.


More Examples

Check if a value is NaN:

isNaN(0/0);
isNaN('');
isNaN('A');
isNaN(true);
isNaN(false);
Try it Yourself »
isNaN('NaN');
isNaN(NaN);
isNaN(undefined);
isNaN(null);
Try it Yourself »

Browser Support

isNaN() is an ECMAScript1 (ES1) feature.

ES1 (JavaScript 1997) is fully supported in all browsers:

Chrome Edge Firefox Safari Opera IE
Yes Yes Yes Yes Yes Yes

Copyright 1999-2023 by Refsnes Data. All Rights Reserved.