JavaScript: isNaN
isNaN
is the value of the property key "isNaN"
of
the Global Object.
console.log( window["isNaN"] === isNaN ); // true
Syntax
isNaN(arg)
- Converts arg to number first, and return
true
if it isNaN
, else,false
. [see NaN]
console.log( isNaN( NaN ) ); // true console.log( isNaN( "NaN" ) ); // true console.log( isNaN( "3" ) ); // false console.log( isNaN( 3 ) ); // false console.log( isNaN( Infinity ) ); // false
isNaN vs Number.isNaN
isNaN
and
Number.isNaN
are different.
The global isNaN
will convert the arg first.
Number.isNaN
does not.
[see Number.isNaN]