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 842315 of NaN

  • Revision slug: Web/JavaScript/Reference/Global_Objects/NaN
  • Revision title: NaN
  • Revision id: 842315
  • Created:
  • Creator: fscholz
  • Is current revision? No
  • Comment fix compat parsing error; cleanup
Tags: 

Revision Content

{{jsSidebar("Objects")}}

The global NaN property is a value representing Not-A-Number.

{{js_property_attributes(0,0,0)}}

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 {{jsxref("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 {{jsxref("Math")}} functions fail (Math.sqrt(-1)) or when a function trying to parse a number fails (parseInt("blabla")).

Testing against NaN

NaN compares unequal (via ==, !=, ===, and !==) to any other value -- including to another NaN value.  Use {{jsxref("Number.isNaN()")}} or {{jsxref("Global_Objects/isNaN", "isNaN()")}} to most clearly determine whether a value is NaN.  Or perform a self-comparison: NaN, and only NaN, will compare unequal to itself.

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

function valueIsNaN(v) { return v !== v; }
valueIsNaN(1);          // false
valueIsNaN(NaN);        // true
valueIsNaN(Number.NaN); // true

Specifications

Specification Status Comment
{{SpecName('ES1')}} {{Spec2('ES1')}} Initial definition. Implemented in JavaScript 1.3
{{SpecName('ES5.1', '#sec-15.1.1.1', 'NaN')}} {{Spec2('ES5.1')}}  
{{SpecName('ES6', '#sec-value-properties-of-the-global-object-nan', 'NaN')}} {{Spec2('ES6')}}  

Browser compatibility

{{CompatibilityTable}}

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}
Feature Android Chrome for Android Firefox Mobile (Gecko) IE Mobile Opera Mobile Safari Mobile
Basic support {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}} {{CompatVersionUnknown}}

See also

  • {{jsxref("Number.NaN")}}
  • {{jsxref("Number.isNaN()")}}
  • {{jsxref("Global_Objects/isNaN", "isNaN()")}}

Revision Source

<div>{{jsSidebar("Objects")}}</div>

<p>The global <code><strong>NaN</strong></code> property is a value representing Not-A-Number.</p>

<p>{{js_property_attributes(0,0,0)}}</p>

<h2 id="Syntax">Syntax</h2>

<pre class="syntaxbox">
<code>NaN</code></pre>

<h2 id="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 {{jsxref("Number.NaN")}}. 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 {{jsxref("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><code>NaN</code> compares unequal (via <code>==,</code> <code>!=,</code> <code>===,</code> and <code>!==)</code> to any other value -- including to another NaN value. &nbsp;Use {{jsxref("Number.isNaN()")}} or {{jsxref("Global_Objects/isNaN", "isNaN()")}} to most clearly determine whether a value is NaN. &nbsp;Or perform a self-comparison: NaN, and only NaN, will compare unequal to itself.</p>

<pre class="brush: js">
NaN === NaN;        // false
Number.NaN === NaN; // false
isNaN(NaN);         // true
isNaN(Number.NaN);  // true

function valueIsNaN(v) { return v !== v; }
valueIsNaN(1);          // false
valueIsNaN(NaN);        // true
valueIsNaN(Number.NaN); // true
</pre>

<h2 id="Specifications">Specifications</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
  <tr>
   <td>{{SpecName('ES1')}}</td>
   <td>{{Spec2('ES1')}}</td>
   <td>Initial definition. Implemented in JavaScript 1.3</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-15.1.1.1', 'NaN')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-value-properties-of-the-global-object-nan', 'NaN')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>&nbsp;</td>
  </tr>
 </tbody>
</table>

<h2 id="Browser_compatibility">Browser compatibility</h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
   <td>{{CompatVersionUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="See_also">See also</h2>

<ul>
 <li>{{jsxref("Number.NaN")}}</li>
 <li>{{jsxref("Number.isNaN()")}}</li>
 <li>{{jsxref("Global_Objects/isNaN", "isNaN()")}}</li>
</ul>
Revert to this revision