aboutsummaryrefslogtreecommitdiff
path: root/files/es/web/javascript/reference/global_objects/null/index.html
blob: 173b31bc50d85a7d061f9591fab80fab1c52e701 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
---
title: 'null'
slug: Web/JavaScript/Reference/Global_Objects/null
tags:
  - JavaScript
  - Literal
  - Primitivo
translation_of: Web/JavaScript/Reference/Global_Objects/null
original_slug: Web/JavaScript/Referencia/Objetos_globales/null
---
<div>{{jsSidebar("Objects")}}</div>

<h2 id="Resumen">Resumen</h2>

<p>El valor <code>null</code> es un literal de Javascript que representa intencionalmente un valor nulo o "vacío". Es uno de los {{Glossary("Primitive", "valores primitivos")}} de Javascript.</p>

<div>{{EmbedInteractiveExample("pages/js/globalprops-null.html")}}</div>



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

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

<h2 id="Description" name="Description">Descripción</h2>

<p>El valor <code>null</code> es un literal (no una propiedad del objeto global como podría ser <code>{{jsxref("undefined", "undefined")}}</code>). En APIs, se devuelve <code>null</code> normalmente dónde se espera un objeto pero éste no es relevante. Al comparar con <code style="font-style: normal;">null</code> o  <code>{{jsxref("undefined", "undefined")}}</code><code> </code>hay que tener en cuenta las <a href="/es/docs/Web/JavaScript/Referencia/Operadores/Comparison_Operators">diferencias entre los operadores de igualdad (==) e identidad (===) </a>(con el primero se realiza una conversión de tipo).</p>

<pre class="brush: js">// foo no existe, no está definido y nunca ha sido inicializado:
&gt; foo
"ReferenceError: foo is not defined"

// foo existe, pero no tiene tipo ni valor:
&gt; var foo = null; foo
"null"
</pre>

<h3 id="Diferencias_entre_null_y_undefined">Diferencias entre <code>null</code><code>undefined</code></h3>

<pre class="brush: js">typeof null        // object (bug en ECMAScript, debería ser null)
typeof undefined   // undefined
null === undefined // false
null  == undefined // true
</pre>

<h2 id="Especificaciones">Especificaciones</h2>

<table class="standard-table">
 <tbody>
  <tr>
   <th scope="col">Especificación</th>
   <th scope="col">Estado</th>
   <th scope="col">Comentarios</th>
  </tr>
  <tr>
   <td>ECMAScript 1st Edition.</td>
   <td>Standard</td>
   <td>Definición inicial.</td>
  </tr>
  <tr>
   <td>{{SpecName('ES5.1', '#sec-4.3.11', 'null value')}}</td>
   <td>{{Spec2('ES5.1')}}</td>
   <td></td>
  </tr>
  <tr>
   <td>{{SpecName('ES6', '#sec-null-value', 'null value')}}</td>
   <td>{{Spec2('ES6')}}</td>
   <td></td>
  </tr>
 </tbody>
</table>

<h2 id="Compatibilidad_con_navegadores">Compatibilidad con navegadores</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">Véase también</h2>

<ul>
 <li>{{jsxref("undefined", "undefined")}}</li>
 <li>{{jsxref("NaN", "NaN")}}</li>
</ul>