★ wanayoo — archive 1999 http://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Number/NaNNouvelle recherche | Portail wanayoo

Mozilla.com

NaN

Summary

A value representing Not-A-Number.

Property of Number
Implemented in: JavaScript 1.1, NES 2.0
ECMA Version: ECMA-262

Description

The value of Number.NaN is Not-A-Number, same as the value of global object's NaN property.

NaN is always unequal to any other number, including NaN itself; you cannot check for the not-a-number value by comparing to Number.NaN. Use the isNaN function instead.

Several JavaScript methods (such as the Number constructor, parseFloat, and parseInt) return NaN if the value specified in the parameter can not be parsed as a number.

You might use the NaN property to indicate an error condition for your function that returns a number in case of success.

JavaScript prints the value Number.NaN as NaN.

Examples

Example: Using NaN

In the following example, if month has a value greater than 12, it is assigned NaN, and a message is displayed indicating valid values.

var month = 13
if (month < 1 || month > 12) {
   month = Number.NaN
   alert("Month must be between 1 and 12.")
}
Languages

Page last modified 18:03, 14 Apr 2007 by Mgjbot

Tags:

Files (0)