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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
---
title: empty
slug: Web/JavaScript/Reference/Statements/Empty
tags:
- Anweisung
- JavaScript
translation_of: Web/JavaScript/Reference/Statements/Empty
---
<div>{{jsSidebar("Statements")}}</div>
<p>Eine <strong>leere Anweisung</strong> dient der Angabe keiner Anweisung, obwohl die JavaScript Syntax eine erwarten würde.</p>
<h2 id="Syntax">Syntax</h2>
<pre class="syntaxbox">;
</pre>
<h2 id="Beschreibung">Beschreibung</h2>
<p>Die leere Anweisung ist ein Semikolon (;) und zeigt an, dass keine Anweisung ausgeführt wird, selbst wenn die JavaScript Syntax eine erfordert. Das gegenteilige Verhalten, bei dem man mehrere Anweisungen haben will, aber JavaScript nur eine einzelne erlaubt, ist die Verwendung einer <a href="/en-US/docs/Web/JavaScript/Reference/Statements/block">Blockanweisung</a>; sie kombiniert mehrere Anweisungen in einer einzelnen.</p>
<h2 id="Beispiele">Beispiele</h2>
<p>Die leere Anweisung wird manchmal in Schleifenanweisungen verwendet. Siehe dazu das folgende Beispiel mit einem leeren Schleifenkörper:</p>
<pre class="brush: js">var arr = [1, 2, 3];
// Alle Arraywerte auf 0 setzen
for (i = 0; i < arr.length; arr[i++] = 0) /* leere Anweisung */ ;
console.log(arr)
// [0, 0, 0]
</pre>
<p><strong>Hinweis:</strong> Es ist gute Praxis, die beabsichtigte Verwendung der leeren Anweisung durch einen Kommentar zu erklären, da der Unterschied zu einem normalen Semikolon nicht offensichtlich ist. In dem folgenden Beispiel ist die Verwendung möglicherweise nicht beabsichtigt:</p>
<pre class="brush: js">if (condition); // Achtung, der "if" Zweig tut nichts!
killTheUniverse() // Daher wird dies hier immer ausgeführt!!!
</pre>
<p>Ein anderes Beispiel: Eine <a href="/en-US/docs/Web/JavaScript/Reference/Statements/if...else"><code>if...else</code></a> Anweisung ohne geschweifte Klammern (<code>{}</code>). Falls <code>three</code> <code>wahr</code> ist, geschieht nichts, <code>four</code> trifft nicht zu und auch die <code>launchRocket()</code> Funktion im <code>else</code> Zweig wird nicht ausgeführt.</p>
<pre class="brush: js">if (one)
doOne();
else if (two)
doTwo();
else if (three)
; // nothing here
else if (four)
doFour();
else
launchRocket();</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('ESDraft', '#sec-empty-statement', 'Empty statement')}}</td>
<td>{{Spec2('ESDraft')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ES6', '#sec-empty-statement', 'Empty statement')}}</td>
<td>{{Spec2('ES6')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ES5.1', '#sec-12.3', 'Empty statement')}}</td>
<td>{{Spec2('ES5.1')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ES3', '#sec-12.3', 'Empty statement')}}</td>
<td>{{Spec2('ES3')}}</td>
<td> </td>
</tr>
<tr>
<td>{{SpecName('ES1', '#sec-12.3', 'Empty statement')}}</td>
<td>{{Spec2('ES1')}}</td>
<td>Initiale Definition.</td>
</tr>
</tbody>
</table>
<h2 id="Browserkompatibilität">Browserkompatibilität</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="Siehe_auch">Siehe auch</h2>
<ul>
<li>{{jsxref("Statements/block", "Blockanweisung")}}</li>
</ul>
|