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

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

Revision Content

{{jsSidebar("Objects")}}

Summary

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 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 {{jsxref("Number.isNaN()")}} or {{jsxref("Global_Objects/isNaN", "isNaN()")}} instead.

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

Specifications

Specification Status Comment
ECMAScript 1st Edition. Standard 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>
 <div>
  <div>
   {{jsSidebar("Objects")}}</div>
 </div>
</div>
<h2 id="Summary">Summary</h2>
<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" 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 {{jsxref("Number.isNaN()")}} or {{jsxref("Global_Objects/isNaN", "isNaN()")}} instead.</p>
<pre class="brush: js">
NaN === NaN;        // false
Number.NaN === NaN; // false
isNaN(NaN);         // true
isNaN(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>ECMAScript 1st Edition.</td>
   <td>Standard</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" name="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