Skip to content

Commit d67c04c

Browse files
committed
minor
1 parent 749e6e1 commit d67c04c

File tree

6 files changed

+48
-55
lines changed

6 files changed

+48
-55
lines changed

1-js/02-first-steps/03-strict-mode/article.md

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ That had the benefit of never breaking the existing codes. But the downside was
66

77
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"`.
88

9-
109
[cut]
1110

1211
## "use strict"
@@ -22,13 +21,12 @@ For example
2221
...
2322
```
2423

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.
2727

28-
Once we enter the strict mode, there's no return.
29-
```
3028

31-
````warn header="Ensure that 'use strict' is at the top"
29+
````warn header="Ensure that \"use strict\" is at the top"
3230
Please make sure that `"use strict"` is on the top of the script, otherwise the strict mode may not be enabled.
3331
3432
There is no strict mode here:
@@ -45,26 +43,21 @@ alert("some code");
4543
Only comments may appear above `"use strict"`.
4644
````
4745

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.
5048

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.
5250
```
5351
52+
## Always "use strict"
5453
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.
6455
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.
6657
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:
6959
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.

1-js/02-first-steps/04-variables/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ It may be interesting to know that there also exist [functional](https://en.wiki
141141
142142
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.
143143
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.
145145
```
146146
147147
## Variable naming [#variable-naming]

1-js/05-data-types/02-number/9-random-int-min-max/solution.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ The simplest, but wrong solution would be to generate a value from `min` to `max
44

55
```js run
66
function randomInteger(min, max) {
7-
let rnd = min + Math.random() * (max - min);
8-
return Math.round(rnd);
7+
let rand = min + Math.random() * (max - min);
8+
return Math.round(rand);
99
}
1010

1111
alert( randomInteger(1, 3) );
@@ -32,9 +32,9 @@ There are many correct solutions to the task. One of them is to adjust interval
3232
```js run
3333
*!*
3434
function randomInteger(min, max) {
35-
// now rnd is from (min-0.5) to (max+0.5)
36-
let rnd = min - 0.5 + Math.random() * (max - min + 1);
37-
return Math.round(rnd);
35+
// now rand is from (min-0.5) to (max+0.5)
36+
let rand = min - 0.5 + Math.random() * (max - min + 1);
37+
return Math.round(rand);
3838
}
3939
*/!*
4040

@@ -46,8 +46,8 @@ An alternative way could be to use `Math.floor` for a random number from `min` t
4646
```js run
4747
*!*
4848
function randomInteger(min, max) {
49-
// here rnd is from min to (max+1)
50-
let rnd = min + Math.random() * (max + 1 - min);
49+
// here rand is from min to (max+1)
50+
let rand = min + Math.random() * (max + 1 - min);
5151
return Math.floor(rand);
5252
}
5353
*/!*
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
11
describe("getLocalDay returns the \"european\" weekday", function() {
22
it("3 January 2014 - friday", function() {
3-
assert.equal(getWeekDay(new Date(2014, 0, 3)), 5);
3+
assert.equal(getLocalDay(new Date(2014, 0, 3)), 5);
44
});
55

66
it("4 January 2014 - saturday", function() {
7-
assert.equal(getWeekDay(new Date(2014, 0, 4)), 6);
7+
assert.equal(getLocalDay(new Date(2014, 0, 4)), 6);
88
});
99

1010
it("5 January 2014 - sunday", function() {
11-
assert.equal(getWeekDay(new Date(2014, 0, 5)), 7);
11+
assert.equal(getLocalDay(new Date(2014, 0, 5)), 7);
1212
});
1313

1414
it("6 January 2014 - monday", function() {
15-
assert.equal(getWeekDay(new Date(2014, 0, 6)), 1);
15+
assert.equal(getLocalDay(new Date(2014, 0, 6)), 1);
1616
});
1717

1818
it("7 January 2014 - tuesday", function() {
19-
assert.equal(getWeekDay(new Date(2014, 0, 7)), 2);
19+
assert.equal(getLocalDay(new Date(2014, 0, 7)), 2);
2020
});
2121

2222
it("8 January 2014 - wednesday", function() {
23-
assert.equal(getWeekDay(new Date(2014, 0, 8)), 3);
23+
assert.equal(getLocalDay(new Date(2014, 0, 8)), 3);
2424
});
2525

2626
it("9 January 2014 - thursday", function() {
27-
assert.equal(getWeekDay(new Date(2014, 0, 9)), 4);
27+
assert.equal(getLocalDay(new Date(2014, 0, 9)), 4);
2828
});
2929
});

1-js/05-data-types/10-date/article.md

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -72,16 +72,16 @@ To create a new `Date` object call `new Date()` with one of the following argume
7272

7373
There are many methods to access the year, month and so on from the `Date` object. But they can be easily remembered when categorized.
7474

75-
`getFullYear()`
75+
[getFullYear()](mdn:js/Date/getFullYear)
7676
: Get the year (4 digits)
7777

78-
`getMonth()`
78+
[getMonth()](mdn:js/Date/getMonth)
7979
: Get the month, **from 0 to 11**.
8080

81-
`getDate()`
81+
[getDate()](mdn:js/Date/getDate)
8282
: Get the day of month, from 1 to 31, the name of the method does look a little bit strange.
8383

84-
`getHours(), getMinutes(), getSeconds(), getMilliseconds()`
84+
[getHours()](mdn:js/Date/getHours), [getMinutes()](mdn:js/Date/getMinutes), [getSeconds()](mdn:js/Date/getSeconds), [getMilliseconds()](mdn:js/Date/getMilliseconds)
8585
: Get the corresponding time components.
8686

8787
```warn header="Not `getYear()`, but `getFullYear()`"
@@ -90,12 +90,12 @@ Many JavaScript engines implement a non-standard method `getYear()`. This method
9090
9191
Additionally, we can get a day of week:
9292
93-
`getDay()`
93+
[getDay()](mdn:js/Date/getDay)
9494
: 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.
9595
9696
**All the methods above return the components relative to the local time zone.**
9797
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"`.
9999
100100
If your local time zone is shifted relative to UTC, then the code below shows different hours:
101101
@@ -112,10 +112,10 @@ alert( date.getUTCHours() );
112112

113113
Besides the given methods, there are two special ones, that do not have a UTC-variant:
114114

115-
`getTime()`
115+
[getTime()](mdn:js/Date/getTime)
116116
: Returns the timestamp for the date -- a number of milliseconds passed from the January 1st of 1970 UTC+0.
117117

118-
`getTimezoneOffset()`
118+
[getTimezoneOffset()](mdn:js/Date/getTimezoneOffset)
119119
: Returns the difference between the local time zone and UTC, in minutes:
120120

121121
```js run
@@ -129,14 +129,14 @@ Besides the given methods, there are two special ones, that do not have a UTC-va
129129

130130
The following methods allow to set date/time components:
131131

132-
- `setFullYear(year [, month, date])`
133-
- `setMonth(month [, date])`
134-
- `setDate(date)`
135-
- `setHours(hour [, min, sec, ms])`
136-
- `setMinutes(min [, sec, ms])`
137-
- `setSeconds(sec [, ms])`
138-
- `setMilliseconds(ms)`
139-
- `setTime(milliseconds)` (sets the whole date by milliseconds since 01.01.1970 UTC)
132+
- [`setFullYear(year [, month, date])`](mdn:js/Date/setFullYear)
133+
- [`setMonth(month [, date])`](mdn:js/Date/setMonth)
134+
- [`setDate(date)`](mdn:js/Date/setDate)
135+
- [`setHours(hour [, min, sec, ms])`](mdn:js/Date/setHours)
136+
- [`setMinutes(min [, sec, ms])`](mdn:js/Date/setMinutes)
137+
- [`setSeconds(sec [, ms])`](mdn:js/Date/setSeconds)
138+
- [`setMilliseconds(ms)`](mdn:js/Date/setMilliseconds)
139+
- [`setTime(milliseconds)`](mdn:js/Date/setTime) (sets the whole date by milliseconds since 01.01.1970 UTC)
140140

141141
Every one of them except `setTime()` has a UTC-variant, for instance: `setUTCHours()`.
142142

2-ui/2-events/01-introduction-browser-events/04-move-ball-field/solution.view/index.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
// the ball has position:absolute, the field: position:relative
4646
// so ball coordinates are relative to the field inner left-upper corner
4747
let ballCoords = {
48-
top: event.clientY - fieldInnerCoords.top - field.clientTop - ball.clientHeight / 2,
49-
left: event.clientX - fieldInnerCoords.left - field.clientLeft - ball.clientWidth / 2
48+
top: event.clientY - fieldCoords.top - field.clientTop - ball.clientHeight / 2,
49+
left: event.clientX - fieldCoords.left - field.clientLeft - ball.clientWidth / 2
5050
};
5151

5252
// prevent crossing the top field boundary

0 commit comments

Comments
 (0)