The isNaN() function determines whether a value is an illegal number (Not-a-Number).
The isNaN() function determines whether a value is an illegal number (Not-a-Number).
This function returns true if the value equates to NaN. Otherwise it returns false.
The global isNaN() function converts the tested value to a Number, then tests it.
Number.isNaN() does not convert the values to a Number, and returns false for non-number type.
isNaN(value)
Parameter | Require | Description |
---|---|---|
value | Required. | The value to be tested |
A Boolean. Returns true if the value is NaN, otherwise it returns false
Check whether a value is NaN:
var res = ""; res = res + isNaN(123) + ": 123\n"; res = res + isNaN(-1.23) + ": -1.23\n"; res = res + isNaN(5-2) + ": 5-2\n"; res = res + isNaN(0) + ": 0\n"; res = res + isNaN('123') + ": '123'\n"; res = res + isNaN('Hello') + ": 'Hello'\n"; res = res + isNaN('2015/12/12') + ": '2015/12/12'\n"; res = res + isNaN('') + ": ''\n"; res = res + isNaN(null) + ": null\n"; res = res + isNaN(true) + ": true\n"; res = res + isNaN(undefined) + ": undefined\n"; res = res + isNaN('NaN') + ": 'NaN'\n"; res = res + isNaN(NaN) + ": NaN\n"; res = res + isNaN(0 / 0) + ": 0 / 0\n"; console.log(res);/* www . j a v a 2 s . com*/