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/01-getting-started/1-intro/article.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -30,7 +30,7 @@ Different engines have different "codenames", for example:
30
30
31
31
The terms above are good to remember, because they are used in developer articles on the internet. We'll use them too. For instance, if "a feature X is supported by V8", then it probably works in Chrome and Opera.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/01-hello-world/article.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ The `<script>` tag has a few attributes that are rarely used nowadays, but we ca
47
47
48
48
The `type` attribute: <code><script <u>type</u>=...></code>
49
49
50
-
: The old standard HTML4 required a script to have a type. Usually it was `type="text/javascript"`. The modern HTML standard assumes this `type` by default. No attribute is required.
50
+
: The old standard HTML4 required a script to have a type. Usually it was `type="text/javascript"`. It's not required any more. Also, the modern standard totally changed the meaning of this attribute. Now it can be used for Javascript modules. But that's an advanced topic, but we'll talk about modules later in another part of the tutorial.
51
51
52
52
The `language` attribute: <code><script <u>language</u>=...></code>
53
53
: This attribute was meant to show the language of the script. As of now, this attribute makes no sense, the language is JavaScript by default. No need to use it.
@@ -61,7 +61,7 @@ Comments before and after scripts.
61
61
//--></script>
62
62
```
63
63
64
-
These comments were supposed to hide the code from an old browser that didn't know about a `<script>` tag. But all browsers born in the past 15+ years don't have any issues. We mention it here, because such comments serve as a sign. If you see that somewhere -- that code is probably really old and not worth looking into.
64
+
This trick isn't used in modern JavaScript. These comments were used to hide the JavaScript code from old browsers that didn't know about a `<script>` tag. Since browsers born in the last 15 years don't have this issue, this kind of comment can help you identify really old code.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/08-comparison/article.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -176,7 +176,7 @@ Yeah, mathematically that's strange. The last result states that "`null` is grea
176
176
177
177
The reason is that an equality check `==` and comparisons `> < >= <=` work differently. Comparisons convert `null` to a number, hence treat it as `0`. That's why (3) `null >= 0` is true and (1) `null > 0` is false.
178
178
179
-
On the other hand, the equality check `==` for `undefined` and `null`works by the rule, without any conversions. They equal each other and don't equal anything else. That's why (2) `null == 0` is false.
179
+
On the other hand, the equality check `==` for `undefined` and `null`is defined such that, without any conversions, they equal each other and don't equal anything else. That's why (2) `null == 0` is false.
Copy file name to clipboardExpand all lines: 1-js/03-code-quality/04-ninja-code/article.md
+6-6
Original file line number
Diff line number
Diff line change
@@ -34,7 +34,7 @@ i = i ? i < 0 ? Math.max(0, len + i) : i : 0;
34
34
35
35
Cool, right? If you write like that, the developer who comes across this line and tries to understand what is the value of `i` is going to have a merry time. Then come to you, seeking for an answer.
36
36
37
-
Tell him that shorter is always better. Initiate him into the paths of ninja.
37
+
Tell them that shorter is always better. Initiate them into the paths of ninja.
38
38
39
39
## One-letter variables
40
40
@@ -45,11 +45,11 @@ completed.
45
45
46
46
Another way to code faster is to use single-letter variable names everywhere. Like `a`, `b` or `c`.
47
47
48
-
A short variable disappears in the code like a real ninja in the forest. No one will be able to find it using "search" of the editor. And even if someone does, he won't be able to "decipher" what the name `a` or `b` means.
48
+
A short variable disappears in the code like a real ninja in the forest. No one will be able to find it using "search" of the editor. And even if someone does, they won't be able to "decipher" what the name `a` or `b` means.
49
49
50
50
...But there's an exception. A real ninja will never use `i` as the counter in a `"for"` loop. Anywhere, but not here. Look around, there are many more exotic letters. For instance, `x` or `y`.
51
51
52
-
An exotic variable as a loop counter is especially cool if the loop body takes 1-2 pages (make it longer if you can). Then if someone looks deep inside the loop, he won't be able to quickly figure out that the variable named `x` is the loop counter.
52
+
An exotic variable as a loop counter is especially cool if the loop body takes 1-2 pages (make it longer if you can). Then if someone looks deep inside the loop, they won't be able to quickly figure out that the variable named `x` is the loop counter.
53
53
54
54
## Use abbreviations
55
55
@@ -153,7 +153,7 @@ function ninjaFunction(elem) {
153
153
}
154
154
```
155
155
156
-
A fellow programmer who wants to work with `elem` in the second half of the function will be surprised... Only during the debugging, after examining the code he will find out that he's working with a clone!
156
+
A fellow programmer who wants to work with `elem` in the second half of the function will be surprised... Only during the debugging, after examining the code they will find out that he's working with a clone!
157
157
158
158
Deadly effective even against an experienced ninja. Seen in code regularly.
159
159
@@ -204,7 +204,7 @@ There are functions that look like they don't change anything. Like `isReady()`,
204
204
205
205
**A really beautiful trick is to add a "useful" action to them, besides the main task.**
206
206
207
-
The expression of dazed surprise on the face of your colleague when he sees a function named `is..`, `check..` or `find...` changing something -- will definitely broaden your boundaries of reason.
207
+
The expression of dazed surprise on the face of your colleague when they see a function named `is..`, `check..` or `find...` changing something -- will definitely broaden your boundaries of reason.
208
208
209
209
**Another way to surprise is to return a non-standard result.**
210
210
@@ -228,7 +228,7 @@ Additional actions should not be obvious from the function name. A true ninja co
228
228
229
229
**Joining several actions into one protects your code from reuse.**
230
230
231
-
Imagine, another developer wants only to check the email, and not output any message. Your function `validateEmail(email)` that does both will not suit him. So he won't break your meditation by asking anything about it.
231
+
Imagine, another developer wants only to check the email, and not output any message. Your function `validateEmail(email)` that does both will not suit them. So they won't break your meditation by asking anything about it.
Copy file name to clipboardExpand all lines: 1-js/03-code-quality/06-polyfills/article.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ Here Babel comes to the rescue.
19
19
20
20
Actually, there are two parts in Babel:
21
21
22
-
1. First, the transpiler program, which rewrites the code. The developer runs it on his own computer. It rewrites the code into the older standard. And then the code is delivered to the website for users. Modern project build system like [webpack](http://webpack.github.io/) or [brunch](http://brunch.io/) provide means to run transpiler automatically on every code change, so that doesn't involve any time loss from our side.
22
+
1. First, the transpiler program, which rewrites the code. The developer runs it on their own computer. It rewrites the code into the older standard. And then the code is delivered to the website for users. Modern project build system like [webpack](http://webpack.github.io/) or [brunch](http://brunch.io/) provide means to run transpiler automatically on every code change, so that doesn't involve any time loss from our side.
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/01-object/article.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -224,7 +224,7 @@ That can become a source of bugs and even vulnerabilies if we intent to store ar
224
224
225
225
In that case the visitor may choose "__proto__" as the key, and the assignment logic will be ruined (as shown above).
226
226
227
-
There is a way to make objects treat `__proto__` as a regular property, which we'll cover later, but first we need to know more about objects.
227
+
There is a way to make objects treat `__proto__` as a regular property, which we'll cover later, but first we need to know more about objects.
228
228
There's also another data structure [Map](info:map-set-weakmap-weakset), that we'll learn in the chapter <info:map-set-weakmap-weakset>, which supports arbitrary keys.
229
229
````
230
230
@@ -701,7 +701,7 @@ alert(clone.sizes.width); // 51, see the result from the other one
701
701
702
702
To fix that, we should use the cloning loop that examines each value of `user[key]` and, if it's an object, then replicate its structure as well. That is called a "deep cloning".
703
703
704
-
There's a standard algorithm for deep cloning that handles the case above and more complex cases, called the [Structured cloning algorithm](https://w3c.github.io/html/infrastructure.html#internal-structured-cloning-algorithm). In order not to reinvent the wheel, we can use a working implementation of it from the JavaScript library [lodash](https://lodash.com), the method is called [_.cloneDeep(obj)](https://lodash.com/docs#cloneDeep).
704
+
There's a standard algorithm for deep cloning that handles the case above and more complex cases, called the [Structured cloning algorithm](http://w3c.github.io/html/infrastructure.html#safe-passing-of-structured-data). In order not to reinvent the wheel, we can use a working implementation of it from the JavaScript library [lodash](https://lodash.com), the method is called [_.cloneDeep(obj)](https://lodash.com/docs#cloneDeep).
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/04-object-methods/article.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -312,7 +312,7 @@ The result of a property access `user.hi` is not a function, but a value of Refe
312
312
(user, "hi", true)
313
313
```
314
314
315
-
When parentheses `()` are called on the Reference Type, they receive the full information about the object and it's method, and can set the right `this` (`=user` in this case).
315
+
When parentheses `()` are called on the Reference Type, they receive the full information about the object and its method, and can set the right `this` (`=user` in this case).
316
316
317
317
Any other operation like assignment `hi = user.hi` discards the reference type as a whole, takes the value of `user.hi` (a function) and passes it on. So any further operation "loses" `this`.
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/06-constructor-new/article.md
+14-4
Original file line number
Diff line number
Diff line change
@@ -85,6 +85,10 @@ The constructor can't be called again, because it is not saved anywhere, just cr
85
85
86
86
## Dual-syntax constructors: new.target
87
87
88
+
```smart header="Advanced stuff"
89
+
The syntax from this section is rarely used, skip it unless you want to know everything.
90
+
```
91
+
88
92
Inside a function, we can check whether it was called with `new` or without it, using a special `new.target` property.
89
93
90
94
It is empty for regular calls and equals the function if called with `new`:
@@ -94,14 +98,18 @@ function User() {
94
98
alert(new.target);
95
99
}
96
100
97
-
// without new:
101
+
// without "new":
102
+
*!*
98
103
User(); // undefined
104
+
*/!*
99
105
100
-
// with new:
106
+
// with "new":
107
+
*!*
101
108
newUser(); // function User { ... }
109
+
*/!*
102
110
```
103
111
104
-
That can be used to allow both `new` and regular syntax to work the same:
112
+
That can be used to allow both `new` and regular calls to work the same. That is, create the same object:
105
113
106
114
```js run
107
115
functionUser(name) {
@@ -116,7 +124,9 @@ let john = User("John"); // redirects call to new User
116
124
alert(john.name); // John
117
125
```
118
126
119
-
This approach is sometimes used in libraries to make the syntax more flexible. Probably not a good thing to use everywhere though, because omitting `new` makes it a bit less obvious what's going on. With `new` we all know that the new object is being created, that's a good thing.
127
+
This approach is sometimes used in libraries to make the syntax more flexible. So that people may call the function with or without `new`, and it still works.
128
+
129
+
Probably not a good thing to use everywhere though, because omitting `new` makes it a bit less obvious what's going on. With `new` we all know that the new object is being created.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/01-primitives-methods/article.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -2,7 +2,7 @@
2
2
3
3
JavaScript allows us to work with primitives (strings, numbers etc) as if they were objects.
4
4
5
-
They also provide methods to call and such. We will study those soon, but first we'll see how it works, because, of course, primitives are not objects (and here we will make it even more clear).
5
+
They also provide methods to call as such. We will study those soon, but first we'll see how it works, because, of course, primitives are not objects (and here we will make it even more clear).
6
6
7
7
Let's look at the key distinction between primitives and objects.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/02-number/article.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -201,7 +201,7 @@ Strange! What is it then if not `0.3`?
201
201
alert( 0.1 + 0.2 ); // 0.30000000000000004
202
202
```
203
203
204
-
Ouch! There are more consequences than an incorrect comparison here. Imagine you're making an e-shopping site and the visitor puts `$0.10` and `$0.20` goods into his chart. The order total will be `$0.30000000000000004`. That would surprise anyone.
204
+
Ouch! There are more consequences than an incorrect comparison here. Imagine you're making an e-shopping site and the visitor puts `$0.10` and `$0.20` goods into their chart. The order total will be `$0.30000000000000004`. That would surprise anyone.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/03-string/article.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -451,7 +451,7 @@ Let's recap these methods to avoid any confusion:
451
451
```smart header="Which one to choose?"
452
452
All of them can do the job. Formally, `substr` has a minor drawback: it is described not in the core JavaScript specification, but in Annex B, which covers browser-only features that exist mainly for historical reasons. So, non-browser environments may fail to support it. But in practice it works everywhere.
453
453
454
-
The author finds himself using `slice` almost all the time.
454
+
The author finds themself using `slice` almost all the time.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/04-array/6-calculator-extendable/task.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -17,7 +17,7 @@ The task consists of two parts.
17
17
18
18
alert( calc.calculate("3 + 7") ); // 10
19
19
```
20
-
2. Then add the method `addOperator(name, func)` that teaches the calculator a newoperation. It takes the operator `name` and the two-argument function `func(a,b)` that implements it.
20
+
2. Then add the method `addMethod(name, func)` that teaches the calculator a newoperation. It takes the operator `name` and the two-argument function `func(a,b)` that implements it.
21
21
22
22
For instance, let's add the multiplication `*`, division `/` and power `**`:
Copy file name to clipboardExpand all lines: 1-js/05-data-types/07-map-set-weakmap-weakset/article.md
+2-2
Original file line number
Diff line number
Diff line change
@@ -47,7 +47,7 @@ For instance:
47
47
```js run
48
48
let john = { name:"John" };
49
49
50
-
// for every user, let's store his visits count
50
+
// for every user, let's store their visits count
51
51
let visitsCountMap =newMap();
52
52
53
53
// john is the key for the map
@@ -332,7 +332,7 @@ That's useful for situations when we have a main storage for the objects somewhe
332
332
333
333
Let's look at an example.
334
334
335
-
For instance, we have code that keeps a visit count for each user. The information is stored in a map: a user is the key and the visit count is the value. When a user leaves, we don't want to store his visit count anymore.
335
+
For instance, we have code that keeps a visit count for each user. The information is stored in a map: a user is the key and the visit count is the value. When a user leaves, we don't want to store their visit count anymore.
336
336
337
337
One way would be to keep track of leaving users and clean up the storage manually:
Copy file name to clipboardExpand all lines: 1-js/06-advanced-functions/03-closure/article.md
+1-1
Original file line number
Diff line number
Diff line change
@@ -175,7 +175,7 @@ The execution flow of the code above:
175
175
176
176
1. The global Lexical Environment has `name: "John"`.
177
177
2. At the line `(*)` the global variable is changed, now it has `name: "Pete"`.
178
-
3. When the function `say()`, is executed and takes `name` from outside. Here that's from the global Lexical Environment where it's already `"Pete"`.
178
+
3. When the function `sayHi()`, is executed and takes `name` from outside. Here that's from the global Lexical Environment where it's already `"Pete"`.
179
179
180
180
181
181
```smart header="One call -- one Lexical Environment"
0 commit comments