JavaScript Number isNaN() method

Definition and usage

In JavaScript,NaN Is the abbreviation for "Not-a-Number".

In JavaScript,NaN It is an invalid number.

If the value is NaN and the type is Number, then Number.isNaN() The method returns true.

See also:

NaN() property

Global isNaN() method

Example

Example 1

Check if the value is Number.NaN:

Number.isNaN(123);
Number.isNaN(-1.23);
Number.isNaN('123');
Number.isNaN(0/0);

Try it yourself

Example 2

Number.isNaN(5-2);
Number.isNaN(0);
Number.isNaN('Hello');
Number.isNaN('2005/12/12');
Number.isNaN(' ');

Try it yourself

Example 3

Check if the value is Number.NaN:

Number.isNaN(false);
Number.isNaN(true);
Number.isNaN(undefined);
Number.isNaN('NaN');
Number.isNaN(NaN);

Try it yourself

Syntax

Number.isNaN(value)

Parameter

Parameter Description
value Required. The value to be tested.

Return value

Type Description
Boolean value. If the value is Number.NaN, then true; otherwise it is false.

Difference between isnan() and Number.isnan()

IfValueIf the value is not a number, then isNaN() The method returns true.

IfNumberIf the value is not a number, then Number.isNaN() Returns true.

In other words:isNaN() Convert the value to a number before testing.

Example

isNaN('Hello');		// Returns true

Try it yourself

Number.isNaN('Hello');	// Returns false

Try it yourself

Browser support

Number.isNaN() Is ECMAScript6 (ES6) feature.

All modern browsers support ES6 (JavaScript 2015):

Chrome Edge Firefox Safari Opera
Chrome Edge Firefox Safari Opera
Supports Supports Supports Supports Supports

Internet Explorer 11 (or earlier versions) does not support Number.isNaN().