Skip to content

Commit 1fc86f8

Browse files
committed
# Conflicts: # 1-js/04-object-basics/03-symbol/article.md # 1-js/09-classes/07-mixins/article.md # 3-frames-and-windows/01-popup-windows/article.md # 9-regular-expressions/01-regexp-introduction/article.md # 9-regular-expressions/03-regexp-character-classes/article.md
2 parents c33b216 + 8c30654 commit 1fc86f8

59 files changed

Lines changed: 670 additions & 453 deletions

File tree

Some content is hidden

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

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/03-code-quality/01-debugging-chrome/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Before writing more complex code, let's talk about debugging.
44

5-
[Debugging](https://en.wikipedia.org/wiki/Debugging) is the process of finding and fixing errors within a script. All modern browsers and most other environments support debugging tools -- a special UI in developer tools that enable debugging much easier. It also allows to trace the code step by step to see what exactly is going on.
5+
[Debugging](https://en.wikipedia.org/wiki/Debugging) is the process of finding and fixing errors within a script. All modern browsers and most other environments support debugging tools -- a special UI in developer tools that makes debugging much easier. It also allows to trace the code step by step to see what exactly is going on.
66

77
We'll be using Chrome here, because it has enough features, most other browsers have a similar process`.
88

1-js/03-code-quality/02-coding-style/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ let n = prompt("n?", "");
2626
2727
if (n < 0) {
2828
alert(`Power ${n} is not supported,
29-
please enter an integer number, greater than 0`);
29+
please enter a non-negative integer number`);
3030
} else {
3131
alert( pow(x, n) );
3232
}

1-js/03-code-quality/02-coding-style/code-style.svg

Lines changed: 1 addition & 1 deletion
Loading

1-js/03-code-quality/05-testing-mocha/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Automated testing with mocha
1+
# Automated testing with Mocha
22

33
Automated testing will be used in further tasks, and it's also widely used in real projects.
44

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: 29 additions & 16 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

@@ -18,7 +18,7 @@ let id = Symbol();
1818

1919
Upon creation, we can give symbol a description (also called a symbol name), mostly useful for debugging purposes:
2020

21-
```js
21+
```js run
2222
// id is a symbol with the description "id"
2323
let id = Symbol("id");
2424
```
@@ -50,36 +50,49 @@ alert(id); // TypeError: Cannot convert a Symbol value to a string
5050
*/!*
5151
```
5252
53-
If we really want to show a symbol, we need to call `.toString()` on it, like here:
53+
That's a "language guard" against messing up, because strings and symbols are fundamentally different and should not accidentally convert one into another.
54+
55+
If we really want to show a symbol, we need to explicitly call `.toString()` on it, like here:
5456
```js run
5557
let id = Symbol("id");
5658
*!*
5759
alert(id.toString()); // Symbol(id), now it works
5860
*/!*
5961
```
6062
61-
That's a "language guard" against messing up, because strings and symbols are fundamentally different and should not occasionally convert one into another.
63+
Or get `symbol.description` property to show the description only:
64+
```js run
65+
let id = Symbol("id");
66+
*!*
67+
alert(id.description); // id
68+
*/!*
69+
```
70+
6271
````
6372

6473
## "Hidden" properties
6574

66-
Symbols allow us to create "hidden" properties of an object, that no other part of code can occasionally access or overwrite.
75+
Symbols allow us to create "hidden" properties of an object, that no other part of code can accidentally access or overwrite.
6776

68-
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.
6978

7079
Let's use a symbol key for it:
7180

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

76-
user[id] = "ID Value";
88+
user[id] = 1;
89+
7790
alert( user[id] ); // we can access the data using the symbol as the key
7891
```
7992

8093
What's the benefit of using `Symbol("id")` over a string `"id"`?
8194

82-
As `user` objects belongs to another code, and that code also works with them, we shouldn't just add any fields to it. That's unsafe. But a symbol cannot be accessed occasionally, the third-party code probably won't even see it, so it's probably all right to do.
95+
As `user` objects belongs to another code, and that code also works with them, we shouldn't just add any fields to it. That's unsafe. But a symbol cannot be accessed accidentally, the third-party code probably won't even see it, so it's probably all right to do.
8396

8497
Also, imagine that another script wants to have its own identifier inside `user`, for its own purposes. That may be another JavaScript library, so that the scripts are completely unaware of each other.
8598

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

102-
// our script uses "id" property
103-
user.id = "ID Value";
115+
// Our script uses "id" property
116+
user.id = "Our id value";
104117

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

107120
user.id = "Their id value"
108-
// boom! overwritten! it did not mean to harm the colleague, but did it!
121+
// Boom! overwritten by another script!
109122
```
110123

111124
### Symbols in a literal
@@ -120,7 +133,7 @@ let id = Symbol("id");
120133
let user = {
121134
name: "John",
122135
*!*
123-
[id]: 123 // not just "id: 123"
136+
[id]: 123 // not "id: 123"
124137
*/!*
125138
};
126139
```
@@ -271,7 +284,7 @@ Symbols are always different values, even if they have the same name. If we want
271284
Symbols have two main use cases:
272285

273286
1. "Hidden" object properties.
274-
If we want to add a property into an object that "belongs" to another script or a library, we can create a symbol and use it as a property key. A symbolic property does not appear in `for..in`, so it won't be occasionally processed together with other properties. Also it won't be accessed directly, because another script does not have our symbol. So the property will be protected from occasional use or overwrite.
287+
If we want to add a property into an object that "belongs" to another script or a library, we can create a symbol and use it as a property key. A symbolic property does not appear in `for..in`, so it won't be accidentally processed together with other properties. Also it won't be accessed directly, because another script does not have our symbol. So the property will be protected from accidental use or overwrite.
275288

276289
So we can "covertly" hide something into objects that we need, but others should not see, using symbolic properties.
277290

1-js/04-object-basics/05-object-toprimitive/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ For instance:
196196
}
197197
};
198198
199-
alert(obj + 2); // 22 (ToPrimitive returned string => concatenation)
199+
alert(obj + 2); // 22 (conversion to primitive returned a string => concatenation)
200200
```
201201

202202
## Summary

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/05-data-types/05-array-methods/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ arr.slice(start, end)
124124

125125
It returns a new array copying to it all items from index `start` to `end` (not including `end`). Both `start` and `end` can be negative, in that case position from array end is assumed.
126126

127-
It's similar to a string method `str.slice`, but instead of substringss it makes subarrays.
127+
It's similar to a string method `str.slice`, but instead of substrings it makes subarrays.
128128

129129
For instance:
130130

0 commit comments

Comments
 (0)