Skip to content

Commit 117a192

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-852ee189
2 parents b48ebc6 + 852ee18 commit 117a192

File tree

77 files changed

+1133
-618
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1133
-618
lines changed

1-js/02-first-steps/12-while-for/article.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,7 @@ for (let i = 0; i < 3; i++) {
309309

310310
let input = prompt(`Value at coords (${i},${j})`, '');
311311

312-
// what if I want to exit from here to Done (below)?
313-
312+
// what if we want to exit from here to Done (below)?
314313
}
315314
}
316315

1-js/04-object-basics/01-object/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ let user = {
154154
};
155155

156156
let key = "name";
157-
user.key // undefined
157+
alert( user.key ) // undefined
158158
```
159159

160160
### Computed properties

1-js/04-object-basics/03-symbol/article.md

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33

44
By specification, object property keys may be either of string type, or of symbol type. Not numbers, not booleans, only strings or symbols, these two types.
55

6-
Till now we've only seen strings. Now let's see the advantages that symbols can give us.
6+
Till now we've been using only strings. Now let's see the benefits that symbols can give us.
77

88
## Symbols
99

10-
"Symbol" value represents a unique identifier.
10+
A "symbol" represents a unique identifier.
1111

1212
A value of this type can be created using `Symbol()`:
1313

@@ -52,15 +52,15 @@ alert(id); // TypeError: Cannot convert a Symbol value to a string
5252
5353
That's a "language guard" against messing up, because strings and symbols are fundamentally different and should not occasionally convert one into another.
5454
55-
If we really want to show a symbol, we need to call `.toString()` on it, like here:
55+
If we really want to show a symbol, we need to explicitly call `.toString()` on it, like here:
5656
```js run
5757
let id = Symbol("id");
5858
*!*
5959
alert(id.toString()); // Symbol(id), now it works
6060
*/!*
6161
```
6262
63-
Or get `symbol.description` property to get the description only:
63+
Or get `symbol.description` property to show the description only:
6464
```js run
6565
let id = Symbol("id");
6666
*!*
@@ -74,15 +74,19 @@ alert(id.description); // id
7474

7575
Symbols allow us to create "hidden" properties of an object, that no other part of code can occasionally access or overwrite.
7676

77-
For instance, if we're working with `user` objects, that belong to a third-party code and don't have any `id` field. We'd like to add identifiers to them.
77+
For instance, if we're working with `user` objects, that belong to a third-party code. We'd like to add identifiers to them.
7878

7979
Let's use a symbol key for it:
8080

8181
```js run
82-
let user = { name: "John" };
82+
let user = { // belongs to another code
83+
name: "John"
84+
};
85+
8386
let id = Symbol("id");
8487

85-
user[id] = "ID Value";
88+
user[id] = 1;
89+
8690
alert( user[id] ); // we can access the data using the symbol as the key
8791
```
8892

@@ -108,13 +112,13 @@ There will be no conflict between our and their identifiers, because symbols are
108112
```js run
109113
let user = { name: "John" };
110114

111-
// our script uses "id" property
112-
user.id = "ID Value";
115+
// Our script uses "id" property
116+
user.id = "Our id value";
113117

114-
// ...if later another script the uses "id" for its purposes...
118+
// ...Another script also wants "id" for its purposes...
115119

116120
user.id = "Their id value"
117-
// boom! overwritten! it did not mean to harm the colleague, but did it!
121+
// Boom! overwritten by another script!
118122
```
119123

120124
### Symbols in a literal
@@ -129,7 +133,7 @@ let id = Symbol("id");
129133
let user = {
130134
name: "John",
131135
*!*
132-
[id]: 123 // not just "id: 123"
136+
[id]: 123 // not "id: 123"
133137
*/!*
134138
};
135139
```

1-js/05-data-types/03-string/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -364,8 +364,8 @@ alert( "Hello".includes("Bye") ); // false
364364
The optional second argument of `str.includes` is the position to start searching from:
365365

366366
```js run
367-
alert( "Midget".includes("id") ); // true
368-
alert( "Midget".includes("id", 3) ); // false, from position 3 there is no "id"
367+
alert( "Widget".includes("id") ); // true
368+
alert( "Widget".includes("id", 3) ); // false, from position 3 there is no "id"
369369
```
370370

371371
The methods [str.startsWith](mdn:js/String/startsWith) and [str.endsWith](mdn:js/String/endsWith) do exactly what they say:

1-js/05-data-types/05-array-methods/9-shuffle/solution.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ There are other good ways to do the task. For instance, there's a great algorith
6868
function shuffle(array) {
6969
for (let i = array.length - 1; i > 0; i--) {
7070
let j = Math.floor(Math.random() * (i + 1)); // random index from 0 to i
71-
[array[i], array[j]] = [array[j], array[i]]; // swap elements
71+
72+
// swap elements array[i] and array[j]
73+
// we use "destructuring assignment" syntax to achieve that
74+
// you'll find more details about that syntax in later chapters
75+
// same can be written as:
76+
// let t = array[i]; array[i] = array[j]; array[j] = t
77+
[array[i], array[j]] = [array[j], array[i]];
7278
}
7379
}
7480
```

1-js/09-classes/07-mixins/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22

33
In JavaScript we can only inherit from a single object. There can be only one `[[Prototype]]` for an object. And a class may extend only one other class.
44

5-
But sometimes that feels limiting. For instance, I have a class `StreetSweeper` and a class `Bicycle`, and want to make their mix: a `StreetSweepingBicycle`.
5+
But sometimes that feels limiting. For instance, we have a class `StreetSweeper` and a class `Bicycle`, and want to make their mix: a `StreetSweepingBicycle`.
66

77
Or we have a class `User` and a class `EventEmitter` that implements event generation, and we'd like to add the functionality of `EventEmitter` to `User`, so that our users can emit events.
88

99
There's a concept that can help here, called "mixins".
1010

11-
As defined in Wikipedia, a [mixin](https://en.wikipedia.org/wiki/Mixin) is a class that contains methods for use by other classes without having to be the parent class of those other classes.
11+
As defined in Wikipedia, a [mixin](https://en.wikipedia.org/wiki/Mixin) is a class containing methods that can be used by other classes without a need to inherit from it.
1212

1313
In other words, a *mixin* provides methods that implement a certain behavior, but we do not use it alone, we use it to add the behavior to other classes.
1414

1-js/10-error-handling/1-try-catch/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,7 @@ try {
298298
*!*
299299
alert(e.name); // SyntaxError
300300
*/!*
301-
alert(e.message); // Unexpected token o in JSON at position 0
301+
alert(e.message); // Unexpected token o in JSON at position 2
302302
}
303303
```
304304

1-js/11-async/01-callbacks/article.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,30 @@ As calls become more nested, the code becomes deeper and increasingly more diffi
223223

224224
That's sometimes called "callback hell" or "pyramid of doom."
225225

226+
<!--
227+
loadScript('1.js', function(error, script) {
228+
if (error) {
229+
handleError(error);
230+
} else {
231+
// ...
232+
loadScript('2.js', function(error, script) {
233+
if (error) {
234+
handleError(error);
235+
} else {
236+
// ...
237+
loadScript('3.js', function(error, script) {
238+
if (error) {
239+
handleError(error);
240+
} else {
241+
// ...
242+
}
243+
});
244+
}
245+
})
246+
}
247+
});
248+
-->
249+
226250
![](callback-hell.svg)
227251

228252
The "pyramid" of nested calls grows to the right with every asynchronous action. Soon it spirals out of control.

1-js/11-async/01-callbacks/callback-hell.svg

Lines changed: 1 addition & 1 deletion
Loading

1-js/11-async/04-promise-error-handling/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@ new Promise((resolve, reject) => {
140140
}
141141

142142
}).then(function() {
143-
/* doesn't runs here */
143+
/* doesn't run here */
144144
}).catch(error => { // (**)
145145

146146
alert(`The unknown error has occurred: ${error}`);
@@ -166,7 +166,7 @@ new Promise(function() {
166166

167167
In case of an error, the promise becomes rejected, and the execution should jump to the closest rejection handler. But there is none. So the error gets "stuck". There's no code to handle it.
168168

169-
In practice, just like with a regular unhandled errors in code, it means that something has terribly gone wrong.
169+
In practice, just like with regular unhandled errors in code, it means that something has terribly gone wrong.
170170

171171
What happens when a regular error occurs and is not caught by `try..catch`? The script dies with a message in console. Similar thing happens with unhandled promise rejections.
172172

1-js/12-generators-iterators/1-generators/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,8 @@ function* generateSequence(start, end) {
239239

240240
Now we'd like to reuse it for generation of a more complex sequence:
241241
- first, digits `0..9` (with character codes 48..57),
242-
- followed by alphabet letters `a..z` (character codes 65..90)
243-
- followed by uppercased letters `A..Z` (character codes 97..122)
242+
- followed by alphabet letters `A..Z` (character codes 65..90)
243+
- followed by uppercased letters `a..z` (character codes 97..122)
244244

245245
We can use this sequence e.g. to create passwords by selecting characters from it (could add syntax characters as well), but let's generate it first.
246246

1-js/12-generators-iterators/2-async-iterators-generators/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -283,7 +283,7 @@ for await (let commit of fetchCommits(repo)) {
283283
}
284284
```
285285
286-
We'd like a call, like `fetchCommits(repo)` to get commits for us, making requests whenever needed. And let it care about all pagination stuff, for us it'll be a simple `for await..of`.
286+
We'd like to make a function `fetchCommits(repo)` that gets commits for us, making requests whenever needed. And let it care about all pagination stuff, for us it'll be a simple `for await..of`.
287287
288288
With async generators that's pretty easy to implement:
289289
@@ -361,4 +361,4 @@ In web-development we often meet streams of data, when it flows chunk-by-chunk.
361361
362362
We can use async generators to process such data, but it's also worth to mention that there's also another API called Streams, that provides special interfaces to work with such streams, to transform the data and to pass it from one stream to another (e.g. download from one place and immediately send elsewhere).
363363
364-
Streams API is not a part of JavaScript language standard.
364+
Streams API is not a part of JavaScript language standard.

1-js/99-js-misc/01-proxy/03-observable/task.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ user.observe((key, value) => {
2020
user.name = "John"; // alerts: SET name=John
2121
```
2222

23-
In other words, an object returned by `makeObservable` has the method `observe(handler)` that allows to add `handler` function to be called on a property change.
23+
In other words, an object returned by `makeObservable` is just like the original one, but also has the method `observe(handler)` that sets `handler` function to be called on any property change.
2424

25-
Whenever a property changes, `handler(key, value)` is called with the name and value o the property.
25+
Whenever a property changes, `handler(key, value)` is called with the name and value of the property.
2626

27-
P.S. In this task, please handle only writing to a property. Other operations can be implemented in a similar way.
27+
P.S. In this task, please only take care about writing to a property. Other operations can be implemented in a similar way.

0 commit comments

Comments
 (0)