|
1 | | -# The modern mode, "use strict" |
| 1 | +# Der moderne Modus, "use strict" |
2 | 2 |
|
3 | | -For a long time, JavaScript evolved without compatibility issues. New features were added to the language while old functionality didn't change. |
| 3 | +JavaScript hat sich lange Zeit ohne Kompatibilitätsprobleme weiterentwickelt. Der Sprache wurden neue Funktionen hinzugefügt, während sich die alten Funktionen nicht geändert haben. |
4 | 4 |
|
5 | | -That had the benefit of never breaking existing code. But the downside was that any mistake or an imperfect decision made by JavaScript's creators got stuck in the language forever. |
| 5 | +Dies hatte den Vorteil, dass der vorhandene Code nie beschädigt wurde. Der Nachteil war jedoch, dass jeder Fehler oder eine Fehlentscheidung der JavaScript-Entwickler für immer in der Sprache hängen blieb. |
6 | 6 |
|
7 | | -This was the case until 2009 when ECMAScript 5 (ES5) appeared. It added new features to the language and modified some of the existing ones. To keep the old code working, most such modifications are off by default. You need to explicitly enable them with a special directive: `"use strict"`. |
| 7 | +Dies war bis zum Erscheinen von ECMAScript 5 (ES5) im Jahr 2009 der Fall. Es wurden der Sprache neue Funktionen hinzugefügt und einige der vorhandenen geändert. Damit der alte Code weiterhin funktioniert, sind die meisten dieser Änderungen standardmäßig deaktiviert. Du musst sie explizit mit einer speziellen Anweisung aktivieren: `"use strict"`. |
8 | 8 |
|
9 | 9 | ## "use strict" |
10 | 10 |
|
11 | | -The directive looks like a string: `"use strict"` or `'use strict'`. When it is located at the top of a script, the whole script works the "modern" way. |
| 11 | +Die Direktive sieht aus wie ein String: `"use strict"` oder `'use strict'`. Wenn es sich am Anfang eines Skripts befindet, funktioniert das gesamte Skript auf "moderne" Weise. |
12 | 12 |
|
13 | | -For example: |
| 13 | +Beispielsweise: |
14 | 14 |
|
15 | 15 | ```js |
16 | 16 | "use strict"; |
17 | 17 |
|
18 | | -// this code works the modern way |
| 18 | +// Dieser Code funktioniert auf moderne Weise |
19 | 19 | ... |
20 | 20 | ``` |
21 | 21 |
|
22 | | -We will learn functions (a way to group commands) soon. Looking ahead, let's note that `"use strict"` can be put at the beginning of the function body instead of the whole script. Doing that enables strict mode in that function only. But usually, people use it for the whole script. |
| 22 | +Wir werden bald Funktionen (eine Möglichkeit, Befehle zu gruppieren) lernen. Mit Blick auf die Zukunft sei angemerkt, dass `"use strict"` anstelle des gesamten Skripts am Anfang des Funktionskörpers stehen kann. Auf diese Weise wird der strikte Modus nur in dieser Funktion aktiviert. Normalerweise wird es jedoch für das gesamte Skript verwendet. |
23 | 23 |
|
24 | 24 |
|
25 | | -````warn header="Ensure that \"use strict\" is at the top" |
26 | | -Please make sure that `"use strict"` is at the top of your scripts, otherwise strict mode may not be enabled. |
| 25 | +````warn header="Stellen sicher, dass \"use strict\" am Anfang steht" |
| 26 | +Stelle sicher, dass `"use strict"` am Anfang deiner Skripte steht, da sonst der strikte Modus möglicherweise nicht aktiv ist. |
27 | 27 |
|
28 | | -Strict mode isn't enabled here: |
| 28 | +Der strikte Modus ist hier nicht aktiviert: |
29 | 29 |
|
30 | 30 | ```js no-strict |
31 | | -alert("some code"); |
32 | | -// "use strict" below is ignored--it must be at the top |
| 31 | +alert("etwas Code"); |
| 32 | +// "use strict" wird ignoriert -- es muss am Anfang stehen |
33 | 33 |
|
34 | 34 | "use strict"; |
35 | 35 |
|
36 | | -// strict mode is not activated |
| 36 | +// Der strikte Modus ist nicht aktiviert |
37 | 37 | ``` |
38 | 38 |
|
39 | | -Only comments may appear above `"use strict"`. |
| 39 | +Nur Kommentare dürfen über `"use strict"` erscheinen. |
40 | 40 | ```` |
41 | 41 |
|
42 | | -```warn header="There's no way to cancel `use strict`" |
43 | | -There is no directive like `"no use strict"` that reverts the engine to old behavior. |
| 42 | +```warn header="Es gibt keine Möglichkeit, `use strict` abzubrechen" |
| 43 | +Es gibt keine Direktive wie `"no use strict"`, die die Engine auf altes Verhalten zurücksetzt. |
44 | 44 |
|
45 | | -Once we enter strict mode, there's no going back. |
| 45 | +Sobald wir in den strikten Modus wechseln, gibt es kein Zurück mehr. |
46 | 46 | ``` |
47 | 47 |
|
48 | | -## Browser console |
| 48 | +## Browser-Konsole |
49 | 49 |
|
50 | | -For the future, when you use a browser console to test features, please note that it doesn't `use strict` by default. |
| 50 | +Wenn du in Zukunft eine Browserkonsole zum Testen von Funktionalitäten verwendest, beachte bitte, dass `use strict` standardmäßig nicht verwendet wird. |
51 | 51 |
|
52 | | -Sometimes, when `use strict` makes a difference, you'll get incorrect results. |
| 52 | +Manchmal, wenn `use strict` einen Unterschied macht, erhältst du falsche Ergebnisse. |
53 | 53 |
|
54 | | -You can try to press `key:Shift+Enter` to input multiple lines, and put `use strict` on top, like this: |
| 54 | +Du kannst versuchen, durch Drücken von `key:Umschalt+Eingabetaste` mehrere Zeilen einzugeben und `use strict` wie folgt an den Anfang zu setzen: |
55 | 55 |
|
56 | 56 | ```js |
57 | | -'use strict'; <Shift+Enter for a newline> |
58 | | -// ...your code |
59 | | -<Enter to run> |
| 57 | +'use strict'; <Umschalt+Eingabe für eine neue Zeile> |
| 58 | +// ...Dein Code |
| 59 | +<Eingabe zum Ausführen> |
60 | 60 | ``` |
61 | 61 |
|
62 | | -It works in most browsers, namely Firefox and Chrome. |
| 62 | +Es funktioniert in den meisten Browsern, wie Firefox und Chrome. |
63 | 63 |
|
64 | | -If it doesn't, the most reliable way to ensure `use strict` would be to input the code into console like this: |
| 64 | +Wenn dies nicht der Fall ist, besteht die zuverlässigste Möglichkeit, um `use strict` sicherzustellen, darin, den Code wie folgt in die Konsole einzugeben: |
65 | 65 |
|
66 | 66 | ```js |
67 | 67 | (function() { |
68 | 68 | 'use strict'; |
69 | 69 |
|
70 | | - // ...your code... |
| 70 | + // ...Dein Code... |
71 | 71 | })() |
72 | 72 | ``` |
73 | 73 |
|
74 | | -## Always "use strict" |
| 74 | +## Immer "use strict" verwenden |
75 | 75 |
|
76 | | -We have yet to cover the differences between strict mode and the "default" mode. |
| 76 | +Wir müssen die Unterschiede zwischen dem striken Modus und dem "Standardmodus" noch behandeln. |
77 | 77 |
|
78 | | -In the next chapters, as we learn language features, we'll note the differences between the strict and default modes. Luckily, there aren't many and they actually make our lives better. |
| 78 | +In den nächsten Kapiteln werden wir beim Erlernen der Sprachfunktionen die Unterschiede zwischen dem Strikten und dem Standardmodus feststellen. Zum Glück gibt es nicht viele und sie verbessern unser Leben. |
79 | 79 |
|
80 | | -For now, it's enough to know about it in general: |
| 80 | +Im Moment genügt es, allgemein zu wissen: |
81 | 81 |
|
82 | | -1. The `"use strict"` directive switches the engine to the "modern" mode, changing the behavior of some built-in features. We'll see the details later in the tutorial. |
83 | | -2. Strict mode is enabled by placing `"use strict"` at the top of a script or function. Several language features, like "classes" and "modules", enable strict mode automatically. |
84 | | -3. Strict mode is supported by all modern browsers. |
85 | | -4. We recommended always starting scripts with `"use strict"`. All examples in this tutorial assume strict mode unless (very rarely) specified otherwise. |
| 82 | +1. Die Anweisung `"use strict"` schaltet die Engine in den "modernen" Modus und ändert das Verhalten einiger eingebauter Funktionen. Wir werden die Details später im Tutorial sehen. |
| 83 | +2. Der strikte Modus wird aktiviert, indem `"use strict"` am Anfang eines Skripts oder einer Funktion platziert wird. Verschiedene Sprachfunktionen, wie "Klassen" und "Module", aktivieren den strikten Modus automatisch. |
| 84 | +3. Der strikte Modus wird von allen modernen Browsern unterstützt. |
| 85 | +4. Wir empfehlen, Skripte immer mit `"use strict"` zu starten. Alle Beispiele in diesen Tutorial gehen von einem strengen Modus aus, sofern nicht (sehr selten) anders angegeben. |
0 commit comments