NaN Number class propertyS2C Home
« Globals « Number « NaN
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 Advanced Tutorials - Lesson 3 - Number