aboutsummaryrefslogtreecommitdiff
path: root/files/de/web/javascript/reference/statements/let/index.html
blob: 5c68f5eb965a71e791c992b681fc0f0671aefd25 (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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
---
title: let
slug: Web/JavaScript/Reference/Statements/let
tags:
  - ECMAScript 2015
  - JavaScript
  - Statement
  - Variable declaration
  - Variables
  - let
translation_of: Web/JavaScript/Reference/Statements/let
---
<div>
<div>
<div>{{jsSidebar("Statements")}}</div>
</div>
</div>

<p>Das Schlüsselwort <strong><code>let</code></strong> deklariert eine Variable im Gültigkeitsbereich des lokalen Blocks. Optional wird die Variable mit einem Wert initialisiert. <strong>let </strong>leitet sich vom englischen Verb "to let" ab, so daß man die Zeile "let x = 3" lesen kann als: "lassen wir x 3 sein" (let x be three), bekannt aus der Programmiersprache BASIC.</p>

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

<pre class="syntaxbox">let var1 [= wert1] [, var2 [= wert2]] [, ..., varN [= wertN]];</pre>

<h3 id="Parameters" name="Parameters">Parameter</h3>

<dl>
 <dt><code>var1</code>, <code>var2</code>, …, <code>varN</code></dt>
 <dd>Variablenname. Jeder legale Bezeichner ist erlaubt.</dd>
 <dt><code>wert1</code>, <code>wert2</code>, …, <code>wertN</code></dt>
 <dd>Initialwerte der Variablen. Jeder legale Ausdruck ist erlaubt.</dd>
</dl>

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

<p><code>let</code> ermöglicht es Variablen zu deklarieren, deren Gültigkeitsbereich auf den Block, den Befehl oder den Ausdruck beschränkt ist, in dem sie deklariert sind. Der Unterschied zum <a href="/de/docs/JavaScript/Reference/Statements/var"><code>var</code></a> Schlüsselwort ist, dass der Gültigkeitsbereich auf Blöcke und nicht auf Funktionen bzw. Global beschränkt ist.</p>

<h3 id="Regeln_für_Gültigkeitsbereiche_2">Regeln für Gültigkeitsbereiche</h3>

<p>Variablen, die mit <code>let</code> deklariert werden, haben als Gültigkeitsbereich den Block in dem sie definiert wurden und alle weiteren Unterblöcke in denen sie nicht neu definiert werden. In dieser Hinsicht funktioniert <code>let</code> ähnlich wie <code>var</code>. Der Unterschied besteht darin, dass der Gültigkeitbereich bei <code>var</code> Deklarierten Variablen die umschließende Funktion ist:</p>

<pre class="brush:js">function varTest() {
  var x = 31;
  if (true) {
    var x = 71;  // gleiche Variable!
    console.log(x);  // 71
  }
  console.log(x);  // 71
}

function letTest() {
  let x = 31;
  if (true) {
    let x = 71;  // andere variable
    console.log(x);  // 71
  }
  console.log(x);  // 31
}</pre>

<p id="Regeln_für_Gültigkeitsbereiche">Auf der ersten Ebene von Programmen und Funktionen erzeugt <code>let</code> im globalen Objekt keine Property, <code>var</code> hingegen schon. Deshalb ist <code>this.y</code> im folgenden Beispiel <code>undefined</code>.</p>

<pre class="brush:js">var x = 'global';
let y = 'global';
console.log(this.x); // "global"
console.log(this.y); // undefined</pre>

<h3 id="Private_Eigenschaften_emulieren">Private Eigenschaften emulieren</h3>

<p>Beim Einsatz von <a href="https://developer.mozilla.org/de/docs/Glossary/Konstruktor">Konstruktoren</a> können <strong><code>let</code></strong>-Deklarationen (alternativ zu <a href="https://developer.mozilla.org/de/docs/Web/JavaScript/Closures">Closures</a>) genutzt werden, um private Eigenschaften in mehreren Methoden zu verwenden.</p>

<pre class="brush:js line-numbers language-js"><code class="language-js"><span class="keyword token">var</span> Thing<span class="punctuation token">;</span>

<span class="punctuation token">{</span>
  <span class="keyword token">let</span> privateScope <span class="operator token">=</span> <span class="keyword token">new</span> <span class="class-name token">WeakMap</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span>
  <span class="keyword token">let</span> counter <span class="operator token">=</span> <span class="number token">0</span><span class="punctuation token">;</span>

  <span class="function function-variable token">Thing</span> <span class="operator token">=</span> <span class="keyword token">function</span><span class="punctuation token">(</span><span class="punctuation token">)</span> <span class="punctuation token">{</span>
    <span class="keyword token">this</span><span class="punctuation token">.</span>someProperty <span class="operator token">=</span> <span class="string token">'foo'</span><span class="punctuation token">;</span>

    privateScope<span class="punctuation token">.</span><span class="function token">set</span><span class="punctuation token">(</span><span class="keyword token">this</span><span class="punctuation token">,</span> <span class="punctuation token">{</span>
      hidden<span class="punctuation token">:</span> <span class="operator token">++</span>counter<span class="punctuation token">,</span>
    <span class="punctuation token">}</span><span class="punctuation token">)</span><span class="punctuation token">;</span>
  <span class="punctuation token">}</span><span class="punctuation token">;</span>

  <span class="class-name token">Thing</span><span class="punctuation token">.</span>prototype<span class="punctuation token">.</span><span class="function function-variable token">showPublic</span> <span class="operator token">=</span> <span class="keyword token">function</span><span class="punctuation token">(</span><span class="punctuation token">)</span> <span class="punctuation token">{</span>
    <span class="keyword token">return</span> <span class="keyword token">this</span><span class="punctuation token">.</span>someProperty<span class="punctuation token">;</span>
  <span class="punctuation token">}</span><span class="punctuation token">;</span>

  <span class="class-name token">Thing</span><span class="punctuation token">.</span>prototype<span class="punctuation token">.</span><span class="function function-variable token">showPrivate</span> <span class="operator token">=</span> <span class="keyword token">function</span><span class="punctuation token">(</span><span class="punctuation token">)</span> <span class="punctuation token">{</span>
    <span class="keyword token">return</span> privateScope<span class="punctuation token">.</span><span class="function token">get</span><span class="punctuation token">(</span><span class="keyword token">this</span><span class="punctuation token">)</span><span class="punctuation token">.</span>hidden<span class="punctuation token">;</span>
  <span class="punctuation token">}</span><span class="punctuation token">;</span>
<span class="punctuation token">}</span>

console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span><span class="keyword token">typeof</span> privateScope<span class="punctuation token">)</span><span class="punctuation token">;</span>
<span class="comment token">// "undefined"</span>

<span class="keyword token">var</span> thing <span class="operator token">=</span> <span class="keyword token">new</span> <span class="class-name token">Thing</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span>

console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>thing<span class="punctuation token">)</span><span class="punctuation token">;</span>
<span class="comment token">// Thing {someProperty: "foo"}</span>

thing<span class="punctuation token">.</span><span class="function token">showPublic</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span>
<span class="comment token">// "foo"</span>

thing<span class="punctuation token">.</span><span class="function token">showPrivate</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span>
<span class="comment token">// 1</span></code></pre>

<p>Das selbe Kapselungsmuster mit Funktionsabschlüssen über lokale Variablen kann mit <code>var</code> erstellt werden, aber dieses benötigt dann funktionsweite Sichtbarkeit (üblicherweise eine IIFE im Modulmuster) anstatt nur blockweite Sichtbarkeit wie das obenstehende Beispiel.</p>

<h3 id="Redeklarationen">Redeklarationen</h3>

<p>Erneute Deklaration derselben Variable innerhalb desselben Gültigkeitsbereiches erzeugt einen Syntaxfehler ({{jsxref("SyntaxError")}}).</p>

<pre class="brush: js example-bad line-numbers language-js"><code class="language-js"><span class="keyword token">if</span> <span class="punctuation token">(</span>x<span class="punctuation token">)</span> <span class="punctuation token">{</span>
  <span class="keyword token">let</span> foo<span class="punctuation token">;</span>
  <span class="keyword token">let</span> foo<span class="punctuation token">;</span> <span class="comment token">// SyntaxError thrown.</span>
<span class="punctuation token">}</span></code></pre>

<p>Der Körper einer <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Statements/switch"><code>switch</code></a>-Anweisung ist nur ein einzelner Block, weshalb das folgende Beispiel einen Fehler verursacht.</p>

<pre class="brush: js example-bad line-numbers language-js"><code class="language-js"><span class="keyword token">let</span> x <span class="operator token">=</span> <span class="number token">1</span><span class="punctuation token">;</span>
<span class="keyword token">switch</span><span class="punctuation token">(</span>x<span class="punctuation token">)</span> <span class="punctuation token">{</span>
  <span class="keyword token">case</span> <span class="number token">0</span><span class="punctuation token">:</span>
    <span class="keyword token">let</span> foo<span class="punctuation token">;</span>
    <span class="keyword token">break</span><span class="punctuation token">;</span>

  <span class="keyword token">case</span> <span class="number token">1</span><span class="punctuation token">:</span>
    <span class="keyword token">let</span> foo<span class="punctuation token">;</span> <span class="comment token">// SyntaxError for redeclaration.</span>
    <span class="keyword token">break</span><span class="punctuation token">;</span>
<span class="punctuation token">}</span></code></pre>

<p>Ist innerhalb einer case-Klausel jedoch ein innerer Block eingebettet, erzeugt dieser seinen eigenen lexikalischen Gültigkeitsbereich. Das folgende Beispiel erzeugt deshalb keine solchen Redeklarations-Fehler, wie sie im vorangegangenen Beispiel auftraten.</p>

<pre class="brush: js line-numbers language-js"><code class="language-js"><span class="keyword token">let</span> x <span class="operator token">=</span> <span class="number token">1</span><span class="punctuation token">;</span>

<span class="keyword token">switch</span><span class="punctuation token">(</span>x<span class="punctuation token">)</span> <span class="punctuation token">{</span>
  <span class="keyword token">case</span> <span class="number token">0</span><span class="punctuation token">:</span> <span class="punctuation token">{</span>
    <span class="keyword token">let</span> foo<span class="punctuation token">;</span>
    <span class="keyword token">break</span><span class="punctuation token">;</span>
  <span class="punctuation token">}</span>
  <span class="keyword token">case</span> <span class="number token">1</span><span class="punctuation token">:</span> <span class="punctuation token">{</span>
    <span class="keyword token">let</span> foo<span class="punctuation token">;</span>
    <span class="keyword token">break</span><span class="punctuation token">;</span>
  <span class="punctuation token">}</span>
<span class="punctuation token">}</span></code></pre>

<h3 id="Sauberer_Quelltext_in_inneren_Funktionen">Sauberer Quelltext in inneren Funktionen</h3>

<p><code>let</code> macht den Programmcode manchmal leserlicher, wenn innere Funktionen eingesetzt werden.</p>

<pre class="brush:js">var list = document.getElementById("list");

for (var i = 1; i &lt;= 5; i++) {
  var item = document.createElement("li");
  item.appendChild(document.createTextNode("Item " + i));

  let j = i;
  item.onclick = function (ev) {
    console.log("Item " + j + " is clicked.");
  };
  list.appendChild(item);
}
</pre>

<p>Dieses Beispiel funktioniert wie erwartet, weil alle fünf Instanzen der anonymen inneren Funktionen auf verschiedene Instanzen der Variable <code>j</code> zugreifen. Wenn stattdessen <code>var</code> verwendet wird oder in der inneren Funktion statt <code>j</code> zu deklarieren <code>i</code> benutzt wird, funktioniert dies nicht.</p>

<h3 id="Zeitweilig_tote_Zonen_und_Fehler_mit_let">Zeitweilig tote Zonen und Fehler mit <code>let</code></h3>

<p>In ECMAScript 2015, werden Deklarationen mit <code>let</code> nicht an den Anfang des Blocks verschoben (hoist). Wird eine Variable vor der Deklaration in einem Block referenziert, führt dies zu einem <code><a href="/de/docs/JavaScript/Reference/Global_Objects/ReferenceError">ReferenceError</a></code>, weil sich die Variable bei Eintritt in den Block bis zur Verarbeitung der Deklaration in einer "zeitweilig toten Zone" (temporal dead zone) befindet.</p>

<pre class="brush: js">function do_something() {
  console.log(foo); // ReferenceError
  let foo = 2;
}</pre>

<p>Ein <a href="/de/docs/JavaScript/Reference/Statements/switch"><code>switch</code></a> Block besteht nur aus einem Block, so dass Fehler wie im folgenden Beispiel auftreten können.</p>

<pre class="brush: js">switch (x) {
  case 0:
    let foo;
    break;

  case 1:
    let foo; // SyntaxError für erneute Deklaration
    break;
}</pre>

<h3 id="Ein_weiteres_Beispiel_zeitweilig_toter_Zonen_mit_lexikalischen_Gültigkeitsbereichen">Ein weiteres Beispiel zeitweilig toter Zonen mit lexikalischen Gültigkeitsbereichen</h3>

<p>Aufgrund seines lexikalischen Gültigkeitsbereiches wird der Bezeichner<strong> "foo"</strong> im untenstehenden Ausdruck <code>(foo + 55)</code> als das foo <u>des if-Blocks</u> interpretiert, <strong>nicht</strong> aber als die <u>verdeckte Variable</u> foo mit dem Wert 33.<br>
 Bei Auswertung des Ausdrucks existiert das foo <u>des if-Blocks</u> bereits im lexikalischen Gültigkeitsbereich, hat seine Initialisierung (welche Teil derselben Anweisung ist) aber noch nicht erreicht (und auch nicht <strong>abgeschlossen</strong>). Folglich ist es noch immer in seiner zeitweilig toten Zone.</p>

<pre class="brush: js example-bad line-numbers language-js"><code class="language-js"><span class="keyword token">function</span> <span class="function token">test</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">{</span>
   <span class="keyword token">var</span> foo <span class="operator token">=</span> <span class="number token">33</span><span class="punctuation token">;</span>
   <span class="keyword token">if</span> <span class="punctuation token">(</span><span class="boolean token">true</span><span class="punctuation token">)</span> <span class="punctuation token">{</span>
      <span class="keyword token">let</span> foo <span class="operator token">=</span> <span class="punctuation token">(</span>foo <span class="operator token">+</span> <span class="number token">55</span><span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// ReferenceError</span>
   <span class="punctuation token">}</span>
<span class="punctuation token">}</span>
<span class="function token">test</span><span class="punctuation token">(</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre>

<p>Dieses Phänomen kann in einer Situation wie der folgenden verwirren. Die Anweisung <code>let n of n.a</code> gehört bereits zum eigenen Gültigkeitsbereich <u>des Blocks der for-Schleife</u>. Der Bezeichner<strong> "n.a"</strong> wird als Eigenschaft 'a' des Objektes 'n' interpretiert, <u>welches im ersten Teil derselben Anweisung deklariert wird</u> ("let n"). Dieses befindet sich noch immer in seiner zeitweilig toten Zone, da bei Auswertung des Ausdrucks die Deklarationsanweisung als noch nicht erreicht und <strong>abgeschlossen</strong> gilt.</p>

<pre class="brush: js example-bad line-numbers language-js"><code class="language-js"><span class="keyword token">function</span> <span class="function token">go</span><span class="punctuation token">(</span><span class="parameter token">n</span><span class="punctuation token">)</span> <span class="punctuation token">{</span>
  <span class="comment token">// n here is defined!</span>
  console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>n<span class="punctuation token">)</span><span class="punctuation token">;</span> <span class="comment token">// Object {a: [1,2,3]}</span>

  <span class="keyword token">for</span> <span class="punctuation token">(</span><span class="keyword token">let</span> n <span class="keyword token">of</span> n<span class="punctuation token">.</span>a<span class="punctuation token">)</span> <span class="punctuation token">{</span> <span class="comment token">// ReferenceError</span>
    console<span class="punctuation token">.</span><span class="function token">log</span><span class="punctuation token">(</span>n<span class="punctuation token">)</span><span class="punctuation token">;</span>
  <span class="punctuation token">}</span>
<span class="punctuation token">}</span>

<span class="function token">go</span><span class="punctuation token">(</span><span class="punctuation token">{</span>a<span class="punctuation token">:</span> <span class="punctuation token">[</span><span class="number token">1</span><span class="punctuation token">,</span> <span class="number token">2</span><span class="punctuation token">,</span> <span class="number token">3</span><span class="punctuation token">]</span><span class="punctuation token">}</span><span class="punctuation token">)</span><span class="punctuation token">;</span></code></pre>

<h2 id="Nicht-standardisierte_let_Ausdrücke">Nicht-standardisierte <code>let</code> Ausdrücke</h2>

<h3 id="let_Blöcke"><code>let</code> Blöcke</h3>

<div class="warning">
<p>Die Unterstützung für <code>let</code> Blöcke wurde in Gecko 44 entfernt ({{bug(1167029)}}).</p>
</div>

<p><strong><code>let</code> Blöcke </strong>ermöglichen es Werte von Variablen in einem Block zu bearbeiten, ohne gleichnamige Variablen außerhalb des Blocks zu beeinflussen.</p>

<h4 id="Syntax_2">Syntax</h4>

<pre class="syntaxbox">let (var1 [= value1] [, var2 [= value2]] [, ..., varN [= valueN]]) block;</pre>

<h4 id="Beschreibung">Beschreibung</h4>

<p>Der <code>let</code> Block unterstützt lokales Scoping für Variablen. Es funktioniert mit dem Binden von keiner oder mehreren Variablen im lexikalischen Scope eines einzigen Blocks. Ansonsten ist es genau das selbe wie ein Block Statement. Zu beachten ist, dass Variablen, die innerhalb des <code>let</code> Blocks mit <code>var</code> definiert werden auch außerhalb des Blocks verfügbar sind, weil diese an die Funktion gebunden werden. Wenn ein <code>let</code> Block-Syntax benutzt wird, ist das <code>let</code> gefolgt von runden Klammern zwingend notwendig. Fehler beim benutzen führen zu einem Syntaxerror.</p>

<h4 id="Beispiel">Beispiel</h4>

<pre class="brush:js">var x = 5;
var y = 0;

let (x = x+10, y = 12) {
  console.log(x+y); // 27
}

console.log(x + y); // 5
</pre>

<p>Die Regeln für den Codeblock sind die gleichen wie für alle anderen Blöcke in JavaScript. Er hat seine Eigenen lokalen Variablen, die mit <code>let</code> deklariert sind.</p>

<h4 id="Regeln_für_Gültigkeitsbereiche_3">Regeln für Gültigkeitsbereiche</h4>

<p>Die Sichtbarkeit von mit <code>let</code> definierten Variablen ist der <code>let</code> Block selbst und auch jeder weitere innere Block in diesem Block, wenn die inneren Blöcke keine Variablen mit dem gleichen Namen definieren.</p>

<h3 id="let_Ausdrücke"><code>let</code> Ausdrücke</h3>

<div class="warning">
<p>Die Unterstützung für <code>let</code> Blöcke wurde in Gecko 41 entfernt ({{bug(1023609)}}).</p>
</div>

<p>Der <strong><code>let</code> Ausdruck</strong> setzt die Sichtbarkeit einer Variablen auf nur einen Ausdruck.</p>

<h4 id="Syntax_3">Syntax</h4>

<pre class="syntaxbox">let (var1 [= value1] [, var2 [= value2]] [, ..., varN [= valueN]]) expression;</pre>

<h4 id="Beispiel_2">Beispiel</h4>

<p>Man kann <code>let</code> benutzen, um Variablen nur für einen Ausdruck zu benutzen:</p>

<pre class="brush: js">var a = 5;
let(a = 6) console.log(a); // 6
console.log(a); // 5</pre>

<h4 id="Regeln_für_Gültigkeitsbereiche_4">Regeln für Gültigkeitsbereiche</h4>

<p>Gegeben ist folgender <code>let</code> Ausdruck:</p>

<pre class="eval">let (<var>decls</var>) <var>expr</var>
</pre>

<p>Es wird ein impliziter Block um <var>expr</var> erstellt.</p>

<h2 id="Name">Name</h2>

<p>Die Erklärung, daß <strong>let</strong> von englisch "to let sth. be sth." abgeleitet ist und so "<strong>let</strong>" als Name (reserviertes Wort) ausgewählt wurde, ist <a href="https://stackoverflow.com/questions/37916940/js-why-let-have-this-name">hier (englisch)</a> zu finden.</p>

<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('ES2015', '#sec-let-and-const-declarations', 'Let and Const Declarations')}}</td>
   <td>{{Spec2('ES2015')}}</td>
   <td>Initiale Definition. Definiert keine let Ausdrücke und let Blöcke.</td>
  </tr>
  <tr>
   <td>{{SpecName('ESDraft', '#sec-let-and-const-declarations', 'Let and Const Declarations')}}</td>
   <td>{{Spec2('ESDraft')}}</td>
   <td></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>Edge</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome(41.0)}}</td>
   <td>12</td>
   <td>{{ CompatGeckoDesktop(44) }}</td>
   <td>11</td>
   <td>17</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td>Temporal dead zone</td>
   <td>{{CompatUnknown}}</td>
   <td>12</td>
   <td>{{ CompatGeckoDesktop(35) }}</td>
   <td>11</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>let</code> expression {{non-standard_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>let</code> block {{non-standard_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td>Allowed in {{Glossary("sloppy mode")}}</td>
   <td>{{CompatChrome(49.0)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatGeckoDesktop(44)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Android Webview</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
   <th>Chrome for Android</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatChrome(41.0)}}</td>
   <td>{{ CompatGeckoMobile(44) }}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatChrome(41.0)}}</td>
  </tr>
  <tr>
   <td>Temporal dead zone</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{ CompatGeckoMobile(35) }}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
  <tr>
   <td><code>let</code> expression {{non-standard_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td><code>let</code> block {{non-standard_inline}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatNo}}</td>
  </tr>
  <tr>
   <td>Allowed in {{Glossary("sloppy mode")}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(49.0)}}</td>
   <td>{{CompatGeckoDesktop(44)}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatUnknown}}</td>
   <td>{{CompatChrome(49.0)}}</td>
  </tr>
 </tbody>
</table>
</div>

<h2 id="Firefox-spezifische_Hinweise">Firefox-spezifische Hinweise</h2>

<ul>
 <li>Vor SpiderMonkey 46 {{geckoRelease(46)}}, wurde ein {{jsxref("TypeError")}} statt einem {{jsxref("SyntaxError")}} erzeugt, wenn Neudeklarationen durchgeführt wurden ({{bug(1198833)}}, {{bug(1275240)}}).</li>
 <li>Vor SpiderMonkey 44 {{geckoRelease(44)}}, war <code>let</code> nur in Quelltexten verfügbar, die im HTML durch ein <code>&lt;script type="application/javascript;version=1.7"&gt;</code> Block umfasst wurden (oder höhere Versionen) und hatte eine andere Semantik.</li>
 <li>Die Unterstützung in {{domxref("Worker")}} Codes ist hinter dem <code>dom.workers.latestJSVersion</code> flag versteckt ({{bug(487070)}}). Mit versionsfreiem <code>let</code>, wird das Flag für diese Funktion entfernt ({{bug(1219523)}}).</li>
 <li>ES2015-Einhaltung für <code>let</code> für SpIderMonkey wird in {{bug(950547)}} nachverfolgt.</li>
</ul>

<h2 id="Siehe_auch">Siehe auch</h2>

<ul>
 <li><a href="/de/docs/Web/JavaScript/Reference/Statements/var"><code>var</code></a></li>
 <li><a href="/de/docs/Web/JavaScript/Reference/Statements/const"><code>const</code></a></li>
 <li><a href="https://hacks.mozilla.org/2015/07/es6-in-depth-let-and-const/">ES6 In Depth: <code>let</code> and <code>const</code></a><a href="http://stackoverflow.com/questions/37916940/js-why-let-have-this-name"> (englisch)</a></li>
 <li><a href="https://blog.mozilla.org/addons/2015/10/14/breaking-changes-let-const-firefox-nightly-44/">Breaking changes in <code>let</code> and <code>const</code> in Firefox 44 </a> <a href="http://stackoverflow.com/questions/37916940/js-why-let-have-this-name"> (englisch)</a></li>
 <li><a href="https://github.com/getify/You-Dont-Know-JS/blob/master/scope%20%26%20closures/ch3.md">You Don't Know JS: Scope &amp; Closures: Chapter 3: Function vs. Block Scope </a> <a href="http://stackoverflow.com/questions/37916940/js-why-let-have-this-name"> (englisch)</a></li>
</ul>