NaN global propertyS2C Home « Globals « 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 NaN global 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 is NaN or not. For this reason we have the isNaN() global function which we can use to determine whether a value is NaN or not.

Syntax

Signature Description
NaNGlobal 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);

Press the button below to action the above code:


Related Tutorials

JavaScript Intermediate Tutorials - Lesson 6 - More Maths Functions

go to home page Homepage go to top of page Top