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 1067640 of null

  • Revision slug: Web/JavaScript/Reference/Global_Objects/null
  • Revision title: null
  • Revision id: 1067640
  • Created:
  • Creator: liammonahan
  • Is current revision? Yes
  • Comment

Revision Content

{{jsSidebar("Objects")}}

The value null represents the intentional absence of any object value. It is one of JavaScript's {{Glossary("Primitive", "primitive values")}}.

Syntax

null 

Description

The value null is written with a literal, null (it's not an identifer for a property of the global object like {{jsxref("Global_Objects/undefined","undefined")}} can be). In APIs, null is often retrieved in place where an object can be expected but no object is relevant. When checking for null or undefined beware of the differences between equality (==) and identity (===) operators (type-conversion is performed with the former).

// foo does not exist. It is not defined and has never been initialized:
> foo
"ReferenceError: foo is not defined"

// foo is known to exist now but it has no type or value:
> var foo = null; foo
"null"

Difference between null and undefined

typeof null        // object (bug in ECMAScript, should be null)
typeof undefined   // undefined
null === undefined // false
null  == undefined // true

Specifications

Specification Status Comment
{{SpecName('ES1')}} {{Spec2('ES1')}} Initial definition.
{{SpecName('ES5.1', '#sec-4.3.11', 'null value')}} {{Spec2('ES5.1')}}  
{{SpecName('ES6', '#sec-null-value', 'null value')}} {{Spec2('ES6')}}  
{{SpecName('ESDraft', '#sec-null-value', 'null value')}} {{Spec2('ESDraft')}}  

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("undefined")}}
  • {{jsxref("NaN")}}

Revision Source

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

<p>The value <code>null</code>&nbsp;represents the intentional absence of any object value. It is one of JavaScript's {{Glossary("Primitive", "primitive values")}}.</p>

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

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

<h2 id="Description">Description</h2>

<p>The value&nbsp;<code>null</code> is written with a literal, <code>null</code>&nbsp;(it's not an identifer for&nbsp;a property of the global object like {{jsxref("Global_Objects/undefined","undefined")}} can be). In APIs, <code>null</code> is often retrieved in place where an object can be expected but no object is relevant. When checking for null or undefined beware of the <a href="/en-US/docs/Web/JavaScript/Reference/Operators/Comparison_Operators">differences between equality (==) and identity (===) operators</a> (type-conversion is performed with the former).</p>

<pre class="brush: js">
// foo does not exist. It is not defined and has never been initialized:
&gt; foo
"ReferenceError: foo is not defined"

// foo is known to exist now but it has no type or value:
&gt; var foo = null; foo
"null"
</pre>

<h3 id="Difference_between_null_and_undefined">Difference between <code>null</code> and <code>undefined</code></h3>

<pre class="brush: js">
typeof null        // object (bug in ECMAScript, should be null)
typeof undefined   // undefined
null === undefined // false
null  == undefined // 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.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-4.3.11', 'null value')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-null-value', 'null value')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td>&nbsp;</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-null-value', 'null value')}}</td>
   <td>{{Spec2('ESDraft')}}</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("undefined")}}</li>
 <li>{{jsxref("NaN")}}</li>
</ul>
Revert to this revision