Skip to content

Commit eb9ea74

Browse files
committed
merging all conflicts
2 parents 0969c74 + 852ee18 commit eb9ea74

File tree

76 files changed

+2778
-368
lines changed

Some content is hidden

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

76 files changed

+2778
-368
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
@@ -308,8 +308,7 @@ for (let i = 0; i < 3; i++) {
308308

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

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

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,20 @@ let key = prompt("What do you want to know about the user?", "name");
146146
alert( user[key] ); // John (if enter "name")
147147
```
148148

149+
<<<<<<< HEAD
150+
=======
151+
The dot notation cannot be used in a similar way:
152+
153+
```js run
154+
let user = {
155+
name: "John",
156+
age: 30
157+
};
158+
159+
let key = "name";
160+
alert( user.key ) // undefined
161+
```
162+
>>>>>>> 852ee189170d9022f67ab6d387aeae76810b5923
149163
150164
### Computed properties
151165

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

Lines changed: 21 additions & 11 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,13 +74,23 @@ 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+
<<<<<<< HEAD
7778
For instance, if we want to store an "identifier" for the object `user`, we can use a symbol as a key for it:
79+
=======
80+
For instance, if we're working with `user` objects, that belong to a third-party code. We'd like to add identifiers to them.
81+
82+
Let's use a symbol key for it:
83+
>>>>>>> 852ee189170d9022f67ab6d387aeae76810b5923
7884
7985
```js run
80-
let user = { name: "John" };
86+
let user = { // belongs to another code
87+
name: "John"
88+
};
89+
8190
let id = Symbol("id");
8291

83-
user[id] = "ID Value";
92+
user[id] = 1;
93+
8494
alert( user[id] ); // we can access the data using the symbol as the key
8595
```
8696

@@ -106,13 +116,13 @@ Now note that if we used a string `"id"` instead of a symbol for the same purpos
106116
```js run
107117
let user = { name: "John" };
108118

109-
// our script uses "id" property
110-
user.id = "ID Value";
119+
// Our script uses "id" property
120+
user.id = "Our id value";
111121

112-
// ...if later another script the uses "id" for its purposes...
122+
// ...Another script also wants "id" for its purposes...
113123

114124
user.id = "Their id value"
115-
// boom! overwritten! it did not mean to harm the colleague, but did it!
125+
// Boom! overwritten by another script!
116126
```
117127

118128
### Symbols in a literal
@@ -127,7 +137,7 @@ let id = Symbol("id");
127137
let user = {
128138
name: "John",
129139
*!*
130-
[id]: 123 // not just "id: 123"
140+
[id]: 123 // not "id: 123"
131141
*/!*
132142
};
133143
```

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

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

357357
```js run
358-
alert( "Midget".includes("id") ); // true
359-
alert( "Midget".includes("id", 3) ); // false, from position 3 there is no "id"
358+
alert( "Widget".includes("id") ); // true
359+
alert( "Widget".includes("id", 3) ); // false, from position 3 there is no "id"
360360
```
361361

362362
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: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,17 @@
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+
<<<<<<< HEAD
56
But sometimes that feels limiting. For instance, I have a class `StreetSweeper` and a class `Bicycle`, and want to make a `StreetSweepingBicycle`.
7+
=======
8+
But sometimes that feels limiting. For instance, we have a class `StreetSweeper` and a class `Bicycle`, and want to make their mix: a `StreetSweepingBicycle`.
9+
>>>>>>> 852ee189170d9022f67ab6d387aeae76810b5923
610
711
Or, talking about programming, we have a class `Renderer` that implements templating and a class `EventEmitter` that implements event handling, and want to merge these functionalities together with a class `Page`, to make a page that can use templates and emit events.
812

913
There's a concept that can help here, called "mixins".
1014

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.
15+
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.
1216

1317
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.
1418

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

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

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

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

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

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

227251
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: 5 additions & 1 deletion
Loading

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,11 @@ new Promise((resolve, reject) => {
150150
}
151151

152152
}).then(function() {
153+
<<<<<<< HEAD
153154
/* never runs here */
155+
=======
156+
/* doesn't run here */
157+
>>>>>>> 852ee189170d9022f67ab6d387aeae76810b5923
154158
}).catch(error => { // (**)
155159

156160
alert(`The unknown error has occurred: ${error}`);
@@ -266,7 +270,11 @@ new Promise(function() {
266270

267271
In case of an error, the promise state becomes "rejected", and the execution should jump to the closest rejection handler. But there is no such handler in the examples above. So the error gets "stuck".
268272

273+
<<<<<<< HEAD
269274
In practice, just like with a regular unhandled errors, it means that something has terribly gone wrong, the script probably died.
275+
=======
276+
In practice, just like with regular unhandled errors in code, it means that something has terribly gone wrong.
277+
>>>>>>> 852ee189170d9022f67ab6d387aeae76810b5923
270278
271279
Most JavaScript engines track such situations and generate a global error in that case. We can see it in the console.
272280

0 commit comments

Comments
 (0)