Javascript - Number isNaN() Method

The Number.isNaN() method determines whether a value is NaN (Not-A-Number).

Description

The Number.isNaN() method determines whether a value is NaN (Not-A-Number).

This method returns true if the value is of the type Number, and evaluated to NaN. Otherwise it returns false.

The global isNaN() function converts the tested value to a Number, then checks if it is a number.

Number.isNaN() does not convert the values to a Number, and will not return true for any value that is not of the type Number.

The value NaN is considered a type of number.

Syntax

Number.isNaN(value)

Parameter Values

Parameter Require Description
value Required. The value to be tested

Return

A Boolean. Returns true if the value is Number.NaN, otherwise it returns false

Example

Check whether a value is NaN:

Demo

var res = "";
res = res + Number.isNaN(123) + ": 123\n";
res = res + Number.isNaN(-1.23) + ": -1.23\n";
res = res + Number.isNaN(5-2) + ": 5-2\n";
res = res + Number.isNaN(0) + ": 0\n";
res = res + Number.isNaN(null) + ": null\n";
res = res + Number.isNaN('123') + ": '123'\n";
res = res + Number.isNaN('d') + ": 'd'\n";
res = res + Number.isNaN('2015/12/12') + ": '2015/12/12'\n";
res = res + Number.isNaN('') + ": ''\n";
res = res + Number.isNaN(true) + ": true\n";
res = res + Number.isNaN(undefined) + ": undefined\n";
res = res + Number.isNaN('NaN') + ": 'NaN'\n";
res = res + Number.isNaN(NaN) + ": NaN\n";
res = res + Number.isNaN(0 / 0) + ": 0 / 0\n";

console.log(res);//ww  w  .  j  a  va  2 s . co  m

Result