Skip to content

Commit 453a42f

Browse files
authored
Merge pull request #216 from javascript-tutorial/sync-7b761858
Sync with upstream @ 7b76185
2 parents f017b6b + 8147267 commit 453a42f

File tree

19 files changed

+177
-119
lines changed

19 files changed

+177
-119
lines changed

1-js/02-first-steps/08-operators/article.md

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -56,17 +56,21 @@ alert( 8 % 3 ); // 2, a remainder of 8 divided by 3
5656

5757
### Exponentiation **
5858

59-
The exponentiation operator `a ** b` multiplies `a` by itself `b` times.
59+
The exponentiation operator `a ** b` raises `a` to the power of `b`.
60+
61+
In school maths, we write that as a<sup>b</sup>.
6062

6163
For instance:
6264

6365
```js run
64-
alert( 2 ** 2 ); // 4 (2 multiplied by itself 2 times)
65-
alert( 2 ** 3 ); // 8 (2 * 2 * 2, 3 times)
66-
alert( 2 ** 4 ); // 16 (2 * 2 * 2 * 2, 4 times)
66+
alert( 2 ** 2 ); // 2² = 4
67+
alert( 2 ** 3 ); // 2³ = 8
68+
alert( 2 ** 4 ); // 2⁴ = 16
6769
```
6870

69-
Mathematically, the exponentiation is defined for non-integer numbers as well. For example, a square root is an exponentiation by `1/2`:
71+
Just like in maths, the exponentiation operator is defined for non-integer numbers as well.
72+
73+
For example, a square root is an exponentiation by ½:
7074

7175
```js run
7276
alert( 4 ** (1/2) ); // 2 (power of 1/2 is the same as a square root)

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,9 +368,18 @@ break label; // jump to the label below (doesn't work)
368368
label: for (...)
369369
```
370370
371-
A call to `continue` is only possible from inside the loop.
371+
A `break` directive must be inside a code block. Technically, any labelled code block will do, e.g.:
372+
```js
373+
label: {
374+
// ...
375+
break label; // works
376+
// ...
377+
}
378+
```
379+
380+
...Although, 99.9% of the time `break` used is inside loops, as we've seen in the examples above.
372381
373-
The `break` directive may be placed before code blocks too, as `label: { ... }`, but it's almost never used like that. And it also works only inside-out.
382+
A `continue` is only possible from inside a loop.
374383
````
375384

376385
## Summary

1-js/02-first-steps/15-function-basics/2-rewrite-function-question-or/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,4 @@ function checkAge(age) {
1414
}
1515
```
1616

17-
Note that the parentheses around `age > 18` are not required here. They exist for better readabilty.
17+
Note that the parentheses around `age > 18` are not required here. They exist for better readability.

1-js/02-first-steps/17-arrow-functions-basics/1-rewrite-arrow/solution.md

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

22
```js run
33
function ask(question, yes, no) {
4-
if (confirm(question)) yes()
4+
if (confirm(question)) yes();
55
else no();
66
}
77

1-js/02-first-steps/17-arrow-functions-basics/1-rewrite-arrow/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Replace Function Expressions with arrow functions in the code below:
55

66
```js run
77
function ask(question, yes, no) {
8-
if (confirm(question)) yes()
8+
if (confirm(question)) yes();
99
else no();
1010
}
1111

1-js/05-data-types/08-weakmap-weakset/01-recipients-read/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ messages.shift();
2525
// now readMessages has 1 element (technically memory may be cleaned later)
2626
```
2727

28-
The `WeakSet` allows to store a set of messages and easily check for the existance of a message in it.
28+
The `WeakSet` allows to store a set of messages and easily check for the existence of a message in it.
2929

3030
It cleans up itself automatically. The tradeoff is that we can't iterate over it, can't get "all read messages" from it directly. But we can do it by iterating over all messages and filtering those that are in the set.
3131

1-js/05-data-types/11-date/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -348,7 +348,7 @@ let time1 = 0;
348348
let time2 = 0;
349349

350350
*!*
351-
// run bench(upperSlice) and bench(upperLoop) each 10 times alternating
351+
// run bench(diffSubtract) and bench(diffGetTime) each 10 times alternating
352352
for (let i = 0; i < 10; i++) {
353353
time1 += bench(diffSubtract);
354354
time2 += bench(diffGetTime);

1-js/06-advanced-functions/03-closure/10-make-army/solution.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,11 +88,11 @@ Let's examine what exactly happens inside `makeArmy`, and the solution will beco
8888
8989
Here `let j = i` declares an "iteration-local" variable `j` and copies `i` into it. Primitives are copied "by value", so we actually get an independent copy of `i`, belonging to the current loop iteration.
9090
91-
The shooters work correctly, because the value of `i` now lives a little bit closer. Not in `makeArmy()` Lexical Environment, but in the Lexical Environment that corresponds the current loop iteration:
91+
The shooters work correctly, because the value of `i` now lives a little bit closer. Not in `makeArmy()` Lexical Environment, but in the Lexical Environment that corresponds to the current loop iteration:
9292
9393
![](lexenv-makearmy-while-fixed.svg)
9494
95-
Such problem could also be avoided if we used `for` in the beginning, like this:
95+
Such a problem could also be avoided if we used `for` in the beginning, like this:
9696
9797
```js run demo
9898
function makeArmy() {

1-js/06-advanced-functions/03-closure/7-let-scope/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ The code above demonstrates it.
2727
function func() {
2828
*!*
2929
// the local variable x is known to the engine from the beginning of the function,
30-
// but "unitialized" (unusable) until let ("dead zone")
30+
// but "uninitialized" (unusable) until let ("dead zone")
3131
// hence the error
3232
*/!*
3333

1-js/06-advanced-functions/03-closure/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ Despite being simple, slightly modified variants of that code have practical use
146146

147147
How does this work? If we create multiple counters, will they be independent? What's going on with the variables here?
148148

149-
Undestanding such things is great for the overall knowledge of JavaScript and beneficial for more complex scenarios. So let's go a bit in-depth.
149+
Understanding such things is great for the overall knowledge of JavaScript and beneficial for more complex scenarios. So let's go a bit in-depth.
150150

151151
## Lexical Environment
152152

1-js/06-advanced-functions/06-function-object/5-sum-many-brackets/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,4 @@ function f(b) {
5252
}
5353
```
5454

55-
This `f` will be used in the next call, again return itself, so many times as needed. Then, when used as a number or a string -- the `toString` returns the `currentSum`. We could also use `Symbol.toPrimitive` or `valueOf` here for the conversion.
55+
This `f` will be used in the next call, again return itself, as many times as needed. Then, when used as a number or a string -- the `toString` returns the `currentSum`. We could also use `Symbol.toPrimitive` or `valueOf` here for the conversion.

1-js/06-advanced-functions/09-call-apply-decorators/04-throttle/solution.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,10 @@ function throttle(func, ms) {
1212
savedThis = this;
1313
return;
1414
}
15+
isThrottled = true;
1516

1617
func.apply(this, arguments); // (1)
1718

18-
isThrottled = true;
19-
2019
setTimeout(function() {
2120
isThrottled = false; // (3)
2221
if (savedArgs) {

1-js/09-classes/01-class/article.md

Lines changed: 21 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class MyClass {
2525
}
2626
```
2727

28-
Then `new MyClass()` creates a new object with all the listed methods.
28+
Then use `new MyClass()` to create a new object with all the listed methods.
2929

3030
The `constructor()` method is called automatically by `new`, so we can initialize the object there.
3131

@@ -53,7 +53,7 @@ When `new User("John")` is called:
5353
1. A new object is created.
5454
2. The `constructor` runs with the given argument and assigns it to `this.name`.
5555

56-
...Then we can call methods, such as `user.sayHi`.
56+
...Then we can call object methods, such as `user.sayHi()`.
5757

5858

5959
```warn header="No comma between class methods"
@@ -64,7 +64,7 @@ The notation here is not to be confused with object literals. Within the class,
6464

6565
## What is a class?
6666

67-
So, what exactly is a `class`? That's not an entirely new language-level entity, as one might think.
67+
So, what exactly is a `class`? That's not an entirely new language-level entity, as one might think.
6868

6969
Let's unveil any magic and see what a class really is. That'll help in understanding many complex aspects.
7070

@@ -85,11 +85,9 @@ alert(typeof User); // function
8585
```
8686

8787
What `class User {...}` construct really does is:
88-
1. Creates a function named `User`, that becomes the result of the class declaration.
89-
- The function code is taken from the `constructor` method (assumed empty if we don't write such method).
90-
3. Stores all methods, such as `sayHi`, in `User.prototype`.
9188

92-
Afterwards, for new objects, when we call a method, it's taken from the prototype, just as described in the chapter <info:function-prototype>. So `new User` object has access to class methods.
89+
1. Creates a function named `User`, that becomes the result of the class declaration. The function code is taken from the `constructor` method (assumed empty if we don't write such method).
90+
2. Stores class methods, such as `sayHi`, in `User.prototype`.
9391

9492
After `new User` object is created, when we call its method, it's taken from the prototype, just as described in the chapter <info:function-prototype>. So the object has access to class methods.
9593

@@ -99,7 +97,6 @@ We can illustrate the result of `class User` declaration as:
9997

10098
Here's the code to introspect it:
10199

102-
103100
```js run
104101
class User {
105102
constructor(name) { this.name = name; }
@@ -113,7 +110,7 @@ alert(typeof User); // function
113110
alert(User === User.prototype.constructor); // true
114111

115112
// The methods are in User.prototype, e.g:
116-
alert(User.prototype.sayHi); // alert(this.name);
113+
alert(User.prototype.sayHi); // the code of the sayHi method
117114

118115
// there are exactly two methods in the prototype
119116
alert(Object.getOwnPropertyNames(User.prototype)); // constructor, sayHi
@@ -171,16 +168,15 @@ Still, there are important differences.
171168
```
172169
There are other differences, we'll see them soon.
173170
174-
2. Class methods are non-enumerable
171+
2. Class methods are non-enumerable.
175172
A class definition sets `enumerable` flag to `false` for all methods in the `"prototype"`.
176173
177174
That's good, because if we `for..in` over an object, we usually don't want its class methods.
178175
179-
3. Classes always `use strict`
176+
3. Classes always `use strict`.
180177
All code inside the class construct is automatically in strict mode.
181178
182-
183-
Also, in addition to its basic operation, the `class` syntax brings many other features with it which we'll explore later.
179+
Besides, `class` syntax brings many other features that we'll explore later.
184180

185181
## Class Expression
186182

@@ -196,21 +192,22 @@ let User = class {
196192
};
197193
```
198194
199-
Similar to Named Function Expressions, class expressions may or may not have a name.
195+
Similar to Named Function Expressions, class expressions may have a name.
200196
201197
If a class expression has a name, it's visible inside the class only:
202198

203199
```js run
204-
// "Named Class Expression" (alas, no such term, but that's what's going on)
200+
// "Named Class Expression"
201+
// (no such term in the spec, but that's similar to Named Function Expression)
205202
let User = class *!*MyClass*/!* {
206203
sayHi() {
207-
alert(MyClass); // MyClass is visible only inside the class
204+
alert(MyClass); // MyClass name is visible only inside the class
208205
}
209206
};
210207
211208
new User().sayHi(); // works, shows MyClass definition
212209
213-
alert(MyClass); // error, MyClass not visible outside of the class
210+
alert(MyClass); // error, MyClass name isn't visible outside of the class
214211
```
215212

216213
We can even make classes dynamically "on-demand", like this:
@@ -243,7 +240,7 @@ class User {
243240
244241
constructor(name) {
245242
// invokes the setter
246-
this._name = name;
243+
this.name = name;
247244
}
248245
249246
*!*
@@ -277,10 +274,11 @@ Technically, such class declaration works by creating getters and setters in `Us
277274
Here's an example with a computed method name using brackets `[...]`:
278275

279276
```js run
280-
function f() { return "sayHi"; }
281-
282277
class User {
283-
[f()]() {
278+
279+
*!*
280+
['say' + 'Hi']() {
281+
*/!*
284282
alert("Hello");
285283
}
286284
@@ -405,29 +403,11 @@ That's especially useful in browser environment, for event listeners.
405403

406404
## Summary
407405

408-
JavaScript provides many ways to create a class.
409-
410-
First, as per the general object-oriented terminology, a class is something that provides "object templates", allows to create same-structured objects.
411-
412-
When we say "a class", that doesn't necessary means the `class` keyword.
413-
414-
This is a class:
415-
416-
```js
417-
function User(name) {
418-
this.sayHi = function() {
419-
alert(name);
420-
}
421-
}
422-
```
423-
424-
...But in most cases `class` keyword is used, as it provides great syntax and many additional features.
425-
426406
The basic class syntax looks like this:
427407

428408
```js
429409
class MyClass {
430-
prop = value; // field
410+
prop = value; // property
431411

432412
constructor(...) { // constructor
433413
// ...
@@ -438,7 +418,7 @@ class MyClass {
438418
get something(...) {} // getter method
439419
set something(...) {} // setter method
440420

441-
[Symbol.iterator]() {} // method with computed name/symbol name
421+
[Symbol.iterator]() {} // method with computed name (symbol here)
442422
// ...
443423
}
444424
```

1-js/11-async/08-async-await/article.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ The function execution "pauses" at the line `(*)` and resumes when the promise s
6969

7070
Let's emphasize: `await` literally suspends the function execution until the promise settles, and then resumes it with the promise result. That doesn't cost any CPU resources, because the JavaScript engine can do other jobs in the meantime: execute other scripts, handle events, etc.
7171

72-
It's just a more elegant syntax of getting the promise result than `promise.then`, easier to read and write.
72+
It's just a more elegant syntax of getting the promise result than `promise.then`. And, it's easier to read and write.
7373

7474
````warn header="Can't use `await` in regular functions"
75-
If we try to use `await` in non-async function, there would be a syntax error:
75+
If we try to use `await` in a non-async function, there would be a syntax error:
7676

7777
```js run
7878
function f() {
@@ -83,7 +83,7 @@ function f() {
8383
}
8484
```
8585

86-
We may get this error if we forget to put `async` before a function. As said, `await` only works inside an `async` function.
86+
We may get this error if we forget to put `async` before a function. As stated earlier, `await` only works inside an `async` function.
8787
````
8888
8989
Let's take the `showAvatar()` example from the chapter <info:promise-chaining> and rewrite it using `async/await`:
@@ -186,7 +186,7 @@ class Waiter {
186186
187187
new Waiter()
188188
.wait()
189-
.then(alert); // 1
189+
.then(alert); // 1 (this is the same as (result => alert(result)))
190190
```
191191
The meaning is the same: it ensures that the returned value is a promise and enables `await`.
192192
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
The HTML in the task is incorrect. That's the reason of the odd thing.
22

3-
The browser has to fix it automatically. But there may be no text inside the `<table>`: according to the spec only table-specific tags are allowed. So the browser adds `"aaa"` *before* the `<table>`.
3+
The browser has to fix it automatically. But there may be no text inside the `<table>`: according to the spec only table-specific tags are allowed. So the browser shows `"aaa"` *before* the `<table>`.
44

55
Now it's obvious that when we remove the table, it remains.
66

7-
The question can be easily answered by exploring the DOM using the browser tools. It shows `"aaa"` before the `<table>`.
7+
The question can be easily answered by exploring the DOM using the browser tools. You'll see `"aaa"` before the `<table>`.
88

99
The HTML standard specifies in detail how to process bad HTML, and such behavior of the browser is correct.

2-ui/3-event-details/4-mouse-drag-and-drop/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ Let's update our algorithm:
124124

125125
```js
126126
// onmousemove
127-
// ball has position:absoute
127+
// ball has position:absolute
128128
ball.style.left = event.pageX - *!*shiftX*/!* + 'px';
129129
ball.style.top = event.pageY - *!*shiftY*/!* + 'px';
130130
```

0 commit comments

Comments
 (0)