Skip to content

Commit e1e22e5

Browse files
authored
Merge pull request #221 from javascript-tutorial/sync-bc08fd1b
Sync with upstream @ bc08fd1
2 parents b37a56e + d7523c0 commit e1e22e5

File tree

31 files changed

+290
-98
lines changed

31 files changed

+290
-98
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Agora, podemos colocar alguns dados usando o operador de atribuição `=`:
2424
let message;
2525

2626
*!*
27-
message = 'Olá'; // armazenar a string
27+
message = 'Olá'; // armazene a string 'Olá' na variável chamada message
2828
*/!*
2929
```
3030

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ label: {
377377
}
378378
```
379379
380-
...Although, 99.9% of the time `break` used is inside loops, as we've seen in the examples above.
380+
...Although, 99.9% of the time `break` is used inside loops, as we've seen in the examples above.
381381
382382
A `continue` is only possible from inside a loop.
383383
````

1-js/02-first-steps/15-function-basics/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ In other words, to put these terms straight:
181181
182182
We declare functions listing their parameters, then call them passing arguments.
183183
184-
In the example above, one might say: "the function `sayMessage` is declared with two parameters, then called with two arguments: `from` and `"Hello"`".
184+
In the example above, one might say: "the function `showMessage` is declared with two parameters, then called with two arguments: `from` and `"Hello"`".
185185
186186
187187
## Default values
@@ -247,7 +247,7 @@ function showMessage(text) {
247247
showMessage(); // empty message
248248
```
249249
250-
...Or we could use the `??` operator:
250+
...Or we could use the `||` operator:
251251
252252
```js
253253
function showMessage(text) {

1-js/03-code-quality/06-polyfills/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ Here, in this chapter, our purpose is to get the gist of how they work, and thei
2222

2323
## Transpilers
2424

25-
A [transpiler](https://en.wikipedia.org/wiki/Source-to-source_compiler) is a special piece of software that can parse ("read and understand") modern code, and rewrite it using older syntax constructs, so that the result would be the same.
25+
A [transpiler](https://en.wikipedia.org/wiki/Source-to-source_compiler) is a special piece of software that translates source code to another source code. It can parse ("read and understand") modern code and rewrite it using older syntax constructs, so that it'll also work in outdated engines.
2626

2727
E.g. JavaScript before year 2020 didn't have the "nullish coalescing operator" `??`. So, if a visitor uses an outdated browser, it may fail to understand the code like `height = height ?? 100`.
2828

1-js/04-object-basics/06-constructor-new/1-two-functions-one-object/task.md

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

55
# Two functions – one object
66

7-
Is it possible to create functions `A` and `B` such as `new A()==new B()`?
7+
Is it possible to create functions `A` and `B` so that `new A() == new B()`?
88

99
```js no-beautify
1010
function A() { ... }

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ In case of such operations, objects are auto-converted to primitives, and then t
99

1010
That's an important limitation, as the result of `obj1 + obj2` can't be another object!
1111

12-
E.g. we can't make objects representing vectors or matrices (or archievements or whatever), add them and expect a "summed" object as the result. Such architectural feats are automatically "off the board".
12+
E.g. we can't make objects representing vectors or matrices (or achievements or whatever), add them and expect a "summed" object as the result. Such architectural feats are automatically "off the board".
1313

1414
So, because we can't do much here, there's no maths with objects in real projects. When it happens, it's usually because of a coding mistake.
1515

@@ -135,7 +135,7 @@ As we can see from the code, `user` becomes a self-descriptive string or a money
135135

136136
If there's no `Symbol.toPrimitive` then JavaScript tries to find methods `toString` and `valueOf`:
137137

138-
- For the "string" hint: `toString`, and if it doesn't exist, then `valueOf` (so `toString` has the priority for stirng conversions).
138+
- For the "string" hint: `toString`, and if it doesn't exist, then `valueOf` (so `toString` has the priority for string conversions).
139139
- For other hints: `valueOf`, and if it doesn't exist, then `toString` (so `valueOf` has the priority for maths).
140140

141141
Methods `toString` and `valueOf` come from ancient times. They are not symbols (symbols did not exist that long ago), but rather "regular" string-named methods. They provide an alternative "old-style" way to implement the conversion.
@@ -279,4 +279,4 @@ The conversion algorithm is:
279279

280280
In practice, it's often enough to implement only `obj.toString()` as a "catch-all" method for string conversions that should return a "human-readable" representation of an object, for logging or debugging purposes.
281281

282-
As for math operations, JavaScript doesn't provide a way to "override" them using methods, so real life projects rarely use them on objects.
282+
As for math operations, JavaScript doesn't provide a way to "override" them using methods, so real life projects rarely use them on objects.

1-js/05-data-types/02-number/article.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ alert( 7.3e9 ); // 7.3 billions (same as 7300000000 or 7_300_000_000)
3737
In other words, `e` multiplies the number by `1` with the given zeroes count.
3838

3939
```js
40-
1e3 = 1 * 1000 // e3 means *1000
41-
1.23e6 = 1.23 * 1000000 // e6 means *1000000
40+
1e3 === 1 * 1000; // e3 means *1000
41+
1.23e6 === 1.23 * 1000000; // e6 means *1000000
4242
```
4343

4444
Now let's write something very small. Say, 1 microsecond (one millionth of a second):
@@ -59,10 +59,10 @@ In other words, a negative number after `"e"` means a division by 1 with the giv
5959

6060
```js
6161
// -3 divides by 1 with 3 zeroes
62-
1e-3 = 1 / 1000 (=0.001)
62+
1e-3 === 1 / 1000; // 0.001
6363

6464
// -6 divides by 1 with 6 zeroes
65-
1.23e-6 = 1.23 / 1000000 (=0.00000123)
65+
1.23e-6 === 1.23 / 1000000; // 0.00000123
6666
```
6767

6868
### Hex, binary and octal numbers
@@ -118,6 +118,7 @@ Please note that two dots in `123456..toString(36)` is not a typo. If we want to
118118
If we placed a single dot: `123456.toString(36)`, then there would be an error, because JavaScript syntax implies the decimal part after the first dot. And if we place one more dot, then JavaScript knows that the decimal part is empty and now goes the method.
119119
120120
Also could write `(123456).toString(36)`.
121+
121122
```
122123

123124
## Rounding

1-js/05-data-types/05-array-methods/12-reduce-object/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ importance: 4
44

55
# Create keyed object from array
66

7-
Let's say we received an array of users in the form `{id:..., name:..., age... }`.
7+
Let's say we received an array of users in the form `{id:..., name:..., age:... }`.
88

99
Create a function `groupById(arr)` that creates an object from it, with `id` as the key, and array items as values.
1010

1-js/05-data-types/09-keys-values-entries/article.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ Objects lack many methods that exist for arrays, e.g. `map`, `filter` and others
7777
If we'd like to apply them, then we can use `Object.entries` followed by `Object.fromEntries`:
7878

7979
1. Use `Object.entries(obj)` to get an array of key/value pairs from `obj`.
80-
2. Use array methods on that array, e.g. `map`.
80+
2. Use array methods on that array, e.g. `map`, to transform these key/value pairs.
8181
3. Use `Object.fromEntries(array)` on the resulting array to turn it back into an object.
8282

8383
For example, we have an object with prices, and would like to double them:
@@ -91,12 +91,13 @@ let prices = {
9191

9292
*!*
9393
let doublePrices = Object.fromEntries(
94-
// convert to array, map, and then fromEntries gives back the object
95-
Object.entries(prices).map(([key, value]) => [key, value * 2])
94+
// convert prices to array, map each key/value pair into another pair
95+
// and then fromEntries gives back the object
96+
Object.entries(prices).map(entry => [entry[0], entry[1] * 2])
9697
);
9798
*/!*
9899

99100
alert(doublePrices.meat); // 8
100-
```
101+
```
101102

102-
It may look difficult at first sight, but becomes easy to understand after you use it once or twice. We can make powerful chains of transforms this way.
103+
It may look difficult at first sight, but becomes easy to understand after you use it once or twice. We can make powerful chains of transforms this way.

1-js/07-object-properties/01-property-descriptors/article.md

Lines changed: 18 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ alert(Object.keys(user)); // name
195195

196196
The non-configurable flag (`configurable:false`) is sometimes preset for built-in objects and properties.
197197

198-
A non-configurable property can not be deleted.
198+
A non-configurable property can't be deleted, its attributes can't be modified.
199199

200200
For instance, `Math.PI` is non-writable, non-enumerable and non-configurable:
201201

@@ -215,20 +215,23 @@ alert( JSON.stringify(descriptor, null, 2 ) );
215215
So, a programmer is unable to change the value of `Math.PI` or overwrite it.
216216

217217
```js run
218-
Math.PI = 3; // Error
218+
Math.PI = 3; // Error, because it has writable: false
219219

220220
// delete Math.PI won't work either
221221
```
222222

223-
Making a property non-configurable is a one-way road. We cannot change it back with `defineProperty`.
223+
We also can't change `Math.PI` to be `writable` again:
224+
225+
```js run
226+
// Error, because of configurable: false
227+
Object.defineProperty(Math, "PI", { writable: true });
228+
```
224229

225-
To be precise, non-configurability imposes several restrictions on `defineProperty`:
226-
1. Can't change `configurable` flag.
227-
2. Can't change `enumerable` flag.
228-
3. Can't change `writable: false` to `true` (the other way round works).
229-
4. Can't change `get/set` for an accessor property (but can assign them if absent).
230+
There's absolutely nothing we can do with `Math.PI`.
230231

231-
**The idea of "configurable: false" is to prevent changes of property flags and its deletion, while allowing to change its value.**
232+
Making a property non-configurable is a one-way road. We cannot change it back with `defineProperty`.
233+
234+
**Please note: `configurable: false` prevents changes of property flags and its deletion, while allowing to change its value.**
232235

233236
Here `user.name` is non-configurable, but we can still change it (as it's writable):
234237

@@ -245,7 +248,7 @@ user.name = "Pete"; // works fine
245248
delete user.name; // Error
246249
```
247250

248-
And here we make `user.name` a "forever sealed" constant:
251+
And here we make `user.name` a "forever sealed" constant, just like the built-in `Math.PI`:
249252

250253
```js run
251254
let user = {
@@ -264,6 +267,11 @@ delete user.name;
264267
Object.defineProperty(user, "name", { value: "Pete" });
265268
```
266269

270+
```smart header="The only attribute change possible: writable true -> false"
271+
There's a minor exception about changing flags.
272+
273+
We can change `writable: true` to `false` for a non-configurable property, thus preventing its value modification (to add another layer of protection). Not the other way around though.
274+
```
267275

268276
## Object.defineProperties
269277

0 commit comments

Comments
 (0)