NaN global property
JS Home <<
JS Reference <<
NaN
Global property that represents the value Not-A-Number.
Description
NaN is returned from functions where parsing to a number fails or from Math functions where a numeric result can't be derived or is unobtainable.
- The
NaNglobal property is also unique in JavaScript in the fact that you cannot rely on the equality (==) and strict equality (===) comparison operators to find out whether a value isNaNor not. For this reason we have theisNaN()global function which we can use to determine whether a value isNaNor not.
Syntax
| Signature | Description |
|---|---|
NaN | Global property that represents the value Not-A-Number. |
Parameters
None.
Below are some examples showing comparisons of NaN and an unobtainable result.
// NaN.
var nanValues = new Array(4);
nanValues[0] = NaN == NaN; // NaN not equal
nanValues[1] = NaN === NaN; // NaN not strict
nanValues[2] = isNaN(NaN); // check against isNaN
nanValues[3] = Number.POSITIVE_INFINITY * 0; // unobtainable
alert(nanValues);
Related Tutorials
JavaScript Intermediate Tutorials - Lesson 6 - More Maths Functions
