Please note, this is a STATIC archive of website developer.mozilla.org from 03 Nov 2016, cach3.com does not collect or store any user information, there is no "phishing" involved.

Revision 418071 of NaN

  • Revision slug: Web/JavaScript/Reference/Global_Objects/NaN
  • Revision title: NaN
  • Revision id: 418071
  • Created:
  • Creator: Sheppy
  • Is current revision? No
  • Comment JavaScript/Reference/Global_Objects/NaN Web/JavaScript/Reference/Global_Objects/NaN
Tags: 

Revision Content

Summary

A value representing Not-A-Number.

Core Global Property
Implemented in JavaScript 1.3
ECMAScript Edition ECMAScript 1st Edition

Syntax

NaN

Description

NaN is a property of the global object.

The initial value of NaN is Not-A-Number — the same as the value of Number.NaN. In modern browsers, NaN is a non-configurable, non-writable property. Even when this is not the case, avoid overriding it.

It is rather rare to use NaN in a program. It is the returned value when Math functions fail (Math.sqrt(-1)) or when a function trying to parse a number fails (parseInt("blabla")).

Testing against NaN

Equality operator (== and ===) cannot be used to test a value against NaN. Use isNaN instead.

NaN === NaN;        // false
Number.NaN === NaN; // false
isNaN(NaN);         // true
isNaN(Number.NaN);  // true

See also

Revision Source

<h2 id="Summary">Summary</h2>
<p>A value representing Not-A-Number.</p>
<table class="standard-table">
  <thead>
    <tr>
      <th class="header" colspan="2">Core Global Property</th>
    </tr>
  </thead>
  <tbody>
    <tr>
      <td>Implemented in</td>
      <td>JavaScript 1.3</td>
    </tr>
    <tr>
      <td>ECMAScript Edition</td>
      <td>ECMAScript 1st Edition</td>
    </tr>
  </tbody>
</table>
<h2 id="Syntax">Syntax</h2>
<p><code>NaN</code></p>
<h2 id="Description" name="Description">Description</h2>
<p><code>NaN</code> is a property of the <em>global object</em>.</p>
<p>The initial value of <code>NaN</code> is Not-A-Number — the same as the value of <code>Number.NaN</code>. In modern browsers, <code>NaN</code> is a non-configurable, non-writable property. Even when this is not the case, avoid overriding it.</p>
<p>It is rather rare to use <code>NaN</code> in a program. It is the returned value when Math functions fail (<code>Math.sqrt(-1)</code>) or when a function trying to parse a number fails (<code>parseInt("blabla")</code>).</p>
<h3 id="Testing_against_NaN">Testing against <code>NaN</code></h3>
<p>Equality operator (<code>==</code> and <code>===</code>) cannot be used to test a value against <code>NaN</code>. Use <a href="/en-US/docs/JavaScript/Reference/Global_Objects/isNaN" title="en-US/docs/JavaScript/Reference/Global_Objects/isNaN"><code>isNaN</code></a> instead.</p>
<pre class="brush: js">
NaN === NaN;        // false
Number.NaN === NaN; // false
isNaN(NaN);         // true
isNaN(Number.NaN);  // true
</pre>
<h2 id="See_also">See also</h2>
<ul>
  <li><a href="/en-US/docs/JavaScript/Reference/Global_Objects/isNaN" title="en-US/docs/Core_JavaScript_1.5_Reference/Global_Functions/isNaN">isNaN</a></li>
</ul>
<!-- languages({
"es": "es/docs/Referencia_de_JavaScript_1.5/Propiedades_globales/NaN",
"fr": "fr/docs/R\u00e9f\u00e9rence_de_JavaScript_1.5_Core/Propri\u00e9t\u00e9s_globales/NaN",
"ja": "ja/docs/JavaScript/Reference/Global_Properties/NaN",
"pl": "pl/docs/Dokumentacja_j\u0119zyka_JavaScript_1.5/W\u0142asno\u015bci/NaN" }) -->
Revert to this revision