mozilla

Revision 72222 of Number.NaN

  • Revision slug: JavaScript/Reference/Global_Objects/Number/NaN
  • Revision title: NaN
  • Revision id: 72222
  • Created:
  • Creator: Sevenspade
  • Is current revision? No
  • Comment /* Summary */ read-only note

Revision Content

Summary

A value representing Not-A-Number.

Read-OnlyProperty 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.

Keep text below in sync with Properties:NaN page 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.")
}

See Also

NaN, isNaN, parseFloat, parseInt

{{ wiki.languages( { "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/Number/NaN" } ) }}

Revision Source

<p>
</p>
<h3 name="Summary"> Summary </h3>
<p>A value representing Not-A-Number.
</p>
<table class="fullwidth-table">
<tbody><tr>
<td class="header" colspan="2"><span class="comment">Read-Only</span>Property of <a href="en/Core_JavaScript_1.5_Reference/Objects/Number">Number</a></td>
</tr>
<tr>
<td>Implemented in:</td>
<td>JavaScript 1.1, NES 2.0</td>
</tr>
<tr>
<td>ECMA Version:</td>
<td>ECMA-262</td>
</tr>
</tbody></table>
<h3 name="Description"> Description </h3>
<p>The value of <code>Number.NaN</code> is Not-A-Number, same as the value of global object's <a href="en/Core_JavaScript_1.5_Reference/Properties/NaN">NaN</a> property.
</p><p><span class="comment">Keep text below in sync with Properties:NaN page</span>
<code>NaN</code> is always unequal to any other number, including <code>NaN</code> itself; you cannot check for the not-a-number value by comparing to <code>Number.NaN</code>. Use the <code><a href="en/Core_JavaScript_1.5_Reference/Functions/isNaN">isNaN</a></code> function instead.
</p><p>Several JavaScript methods (such as the <code>Number</code> constructor, <code>parseFloat</code>, and <code>parseInt</code>) return <code>NaN</code> if the value specified in the parameter can not be parsed as a number.
</p><p>You might use the <code>NaN</code> property to indicate an error condition for your function that returns a number in case of success.
</p><p>JavaScript prints the value <code>Number.NaN</code> as <code>NaN</code>.
</p>
<h3 name="Examples"> Examples </h3>
<h4 name="Example:_Using_NaN"> Example: Using <code>NaN</code> </h4>
<p>In the following example, if month has a value greater than 12, it is assigned <code>NaN</code>, and a message is displayed indicating valid values.
</p>
<pre>var month = 13
if (month &lt; 1 || month &gt; 12) {
   month = Number.NaN
   alert("Month must be between 1 and 12.")
}
</pre>
<h3 name="See_Also"> See Also </h3>
<p><a href="en/Core_JavaScript_1.5_Reference/Properties/NaN">NaN</a>,
<a href="en/Core_JavaScript_1.5_Reference/Functions/isNaN">isNaN</a>,
<a href="en/Core_JavaScript_1.5_Reference/Functions/parseFloat">parseFloat</a>,
<a href="en/Core_JavaScript_1.5_Reference/Functions/parseInt">parseInt</a>
</p>{{ wiki.languages( { "pl": "pl/Dokumentacja_j\u0119zyka_JavaScript_1.5/Obiekty/Number/NaN" } ) }}
Revert to this revision