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
|
---
title: 'null'
slug: Web/JavaScript/Reference/Global_Objects/null
tags:
- JavaScript
- Literal
- Primitive
translation_of: Web/JavaScript/Reference/Global_Objects/null
---
<div>{{jsSidebar("Objects")}}</div>
<p>Der Wert <code>null</code> repräsentiert das absichtliche Fehlen eines Wertes. Es ist einer der {{Glossary("Primitive", "Primitiven Werte")}} in Javascript.</p>
<div>{{EmbedInteractiveExample("pages/js/globalprops-null.html")}}</div>
<h2 id="Syntax" name="Syntax">Syntax</h2>
<pre class="syntaxbox"><code>null </code></pre>
<h2 id="Description" name="Description">Beschreibung</h2>
<p>Der Wert <code>null</code> wird als Literal geschrieben: <code>null</code>. Der Wert <code>null</code> ist ein Literal (keine Eigenschaft des <em>globalen Objektes</em> wie<em> </em>{{jsxref("Global_Objects/undefined", "undefined")}}). <span id="result_box" lang="de"><span>Stattdessen drückt null einen Mangel an Identifikation aus und zeigt an, dass eine Variable auf kein Objekt zeigt</span></span>. In APIs wird <code>null</code> oftmals an Stellen verwendet, an denen ein Objekt optional genutzt werden kann.</p>
<pre class="brush: js">// foo existiert nicht. Es wurde nicht definiert und nirgendwo initialisiert:
foo;
"ReferenceError: foo is not defined"
// foo existiert nun, aber die Variable hat keinen Typ oder Wert:
var foo = null;
foo;
"null"
</pre>
<h3 id="Unterschied_zwischen_null_und_undefined">Unterschied zwischen <code>null</code> und <code>undefined</code></h3>
<p>Wenn auf null geprüft wird, sollte nicht der Gleichheitsvergleich ({{jsxref("Operators/Comparison_Operators", "==", "#Equality")}}) mit dem Identitätsvergleich ({{jsxref("Operators/Comparison_Operators", "===", "#Identity")}}) verwechselt werden, weil bei der Prüfung auf Gleichheit eine <span class="dpf_sent" id="dpfsent_3">implizite </span>Typumwandlung vorgenommen wird.</p>
<pre class="brush: js">typeof null // "object" (not "null" for legacy reasons)
typeof undefined // "undefined"
null === undefined // false
null == undefined // true
null === null // true
null == null // true
!null // true
isNaN(1 + null) // false
isNaN(1 + undefined) // true</pre>
<h2 id="Spezifikationen">Spezifikationen</h2>
<table class="standard-table">
<tbody>
<tr>
<th scope="col">Spezifikation</th>
<th scope="col">Status</th>
<th scope="col">Kommentar</th>
</tr>
<tr>
<td>{{SpecName('ES1')}}</td>
<td>{{Spec2('ES1')}}</td>
<td>Initiale Definition.</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>
<tr>
<td>{{SpecName('ESDraft', '#sec-null-value', 'null value')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td> </td>
</tr>
</tbody>
</table>
<h2 id="Browserkompatibilität">Browserkompatibilität</h2>
<p>{{Compat("javascript.builtins.null")}}</p>
<h2 id="See_also" name="See_also">Siehe auch</h2>
<ul>
<li>{{jsxref("undefined")}}</li>
<li>{{jsxref("NaN")}}</li>
</ul>
|