You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/03-strict-mode/article.md
+15-22Lines changed: 15 additions & 22 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,6 @@ That had the benefit of never breaking the existing codes. But the downside was
6
6
7
7
It had been so 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 modifications are off by default. One needs to enable them explicitly with a special directive `"use strict"`.
8
8
9
-
10
9
[cut]
11
10
12
11
## "use strict"
@@ -22,13 +21,12 @@ For example
22
21
...
23
22
```
24
23
25
-
```warn header="There's no way to cancel `use strict`"
26
-
There is no directive `"no use strict"` or alike, that would return the old behavior.
24
+
We will learn functions (a way to group commands) soon.
25
+
26
+
Looking ahead let's just note that `"use strict"` can be put at the start of a function (most kinds of functions) instead of the whole script. Then strict mode is enabled in that function only. But usually people use it for the whole script.
27
27
28
-
Once we enter the strict mode, there's no return.
29
-
```
30
28
31
-
````warn header="Ensure that 'use strict' is at the top"
29
+
````warn header="Ensure that \"use strict\" is at the top"
32
30
Please make sure that `"use strict"` is on the top of the script, otherwise the strict mode may not be enabled.
33
31
34
32
There is no strict mode here:
@@ -45,26 +43,21 @@ alert("some code");
45
43
Only comments may appear above `"use strict"`.
46
44
````
47
45
48
-
```smart header="`use strict` for functions"
49
-
We will learn functions (a way to group commands) soon.
46
+
```warn header="There's no way to cancel `use strict`"
47
+
There is no directive `"no use strict"` or alike, that would return the old behavior.
50
48
51
-
Looking ahead let's just note that `"use strict"` can be put at the start of a function (most kinds of functions) instead of the whole script. Then strict mode is enabled in that function only. But usually people use it for the whole script.
49
+
Once we enter the strict mode, there's no return.
52
50
```
53
51
52
+
## Always "use strict"
54
53
55
-
## Start with "use strict"
56
-
57
-
It is recommended to always start a script with `"use strict"`, for the following reasons:
58
-
59
-
1. First, all modern browsers support it. Only outdated ones like Internet Explorer 9 and below do not.
60
-
2. Second, the modern JavaScript actually forces us into the strict mode. There are several modern language features like "classes" and "modules" that enable strict mode automatically. So, it's hard to evade it.
61
-
3. The last, but not the least: strict mode is the modern mode. Makes the language a little bit better in few aspects. We'll see that as we study more language features.
62
-
63
-
Here in the tutorial, all code (where not explicitly noted otherwise) works in `"use strict"`. We concentrate on modern JavaScript. But there will be notes about what happens without `"use strict"`, so that you can understand what's going on if you forget it or if you're working with an outdated script that doesn't have it.
54
+
The differences of `"use strict"` versus the "default" mode are still to be covered.
64
55
65
-
## Summary
56
+
In the next chapters, as we learn language features, we'll make notes about the differences of the strict mode. Luckily, there are not so many. And they actually make our life better.
66
57
67
-
- The `"use strict"` directive switches the engine to the "modern" mode, changing the behavior of some built-in features.
68
-
- Several modern features of the language enable `"use strict"` implicitly, so it's quite hard to evade it.
58
+
At this point of time it's enough to know about it in general:
69
59
70
-
It's always recommended to start scripts with `"use strict"`. All examples in this tutorial assume so, unless (very rarely) specified otherwise.
60
+
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 as we study.
61
+
2. The strict mode is enabled by `"use strict"` at the top. Also there are several language features like "classes" and "modules" that enable strict mode automatically.
62
+
3. The strict mode is supported by all modern browsers.
63
+
4. It's always recommended to start scripts with `"use strict"`. All examples in this tutorial assume so, unless (very rarely) specified otherwise.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/04-variables/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -141,7 +141,7 @@ It may be interesting to know that there also exist [functional](https://en.wiki
141
141
142
142
In such languages, once the value is stored "in the box" -- it's there forever. If we need to store something else -- the language forces to create a new box (declare a new variable), we can't reuse the old one.
143
143
144
-
Though it may seem a little bit odd at first sight, these languages are quite capable of serious development. More than that, there are areas like parallel computations where this limitation infers certain benefits. Studying of such a language (even if not planning to use it soon) is recommended to broaden the mind.
144
+
Though it may seem a little bit odd at first sight, these languages are quite capable of serious development. More than that, there are areas like parallel computations where this limitation confers certain benefits. Studying of such a language (even if not planning to use it soon) is recommended to broaden the mind.
```warn header="Not `getYear()`, but `getFullYear()`"
@@ -90,12 +90,12 @@ Many JavaScript engines implement a non-standard method `getYear()`. This method
90
90
91
91
Additionally, we can get a day of week:
92
92
93
-
`getDay()`
93
+
[getDay()](mdn:js/Date/getDay)
94
94
: Get the day of week, from `0` (Sunday) to `6` (Saturday). The first day is always Sunday, in some countries that's not so, but can't be changed.
95
95
96
96
**All the methods above return the components relative to the local time zone.**
97
97
98
-
There are also their UTC-counterparts, that return day, month, year and so on for the time zone UTC+0: `getUTCFullYear()`, `getUTCMonth()`, `getUTCDay()`. Just insert the `"UTC"` right after `"get"`.
98
+
There are also their UTC-counterparts, that return day, month, year and so on for the time zone UTC+0: [getUTCFullYear()](mdn:js/Date/getUTCFullYear), [getUTCMonth()](mdn:js/Date/getUTCMonth), [getUTCDay()](mdn:js/Date/getUTCDay). Just insert the `"UTC"` right after `"get"`.
99
99
100
100
If your local time zone is shifted relative to UTC, then the code below shows different hours:
0 commit comments