Skip to content

Commit 17d248e

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-bae0ef44
2 parents 08ed816 + bae0ef4 commit 17d248e

File tree

16 files changed

+37
-22
lines changed

16 files changed

+37
-22
lines changed

1-js/02-first-steps/05-types/article.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,15 @@ Besides regular numbers, there are so-called "special numeric values" which also
4646
alert( "not a number" / 2 ); // NaN, such division is erroneous
4747
```
4848

49-
`NaN` is sticky. Any further operation on `NaN` returns `NaN`:
49+
`NaN` is sticky. Any further mathematical operation on `NaN` returns `NaN`:
5050

5151
```js run
52-
alert( "not a number" / 2 + 5 ); // NaN
52+
alert( NaN + 1 ); // NaN
53+
alert( 3 * NaN ); // NaN
54+
alert( "not a number" / 2 - 1 ); // NaN
5355
```
5456

55-
So, if there's a `NaN` somewhere in a mathematical expression, it propagates to the whole result.
57+
So, if there's a `NaN` somewhere in a mathematical expression, it propagates to the whole result (there's only one exception to that: `NaN ** 0` is `1`).
5658

5759
```smart header="Mathematical operations are safe"
5860
Doing maths is "safe" in JavaScript. We can do anything: divide by zero, treat non-numeric strings as numbers, etc.

1-js/02-first-steps/12-nullish-coalescing-operator/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ In practice, the zero height is often a valid value, that shouldn't be replaced
106106
107107
## Precedence
108108
109-
The precedence of the `??` operator is about the same as `||`, just a bit lower. It equals `5` in the [MDN table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table), while `||` is `6`.
109+
The precedence of the `??` operator is the same as `||`. They both equal `4` in the [MDN table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table).
110110
111111
That means that, just like `||`, the nullish coalescing operator `??` is evaluated before `=` and `?`, but after most other operations, such as `+`, `*`.
112112

1-js/02-first-steps/16-function-expressions/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ function sayHi() {
1212

1313
There is another syntax for creating a function that is called a *Function Expression*.
1414

15-
It allows to create a new function in the middle of any expression.
15+
It allows us to create a new function in the middle of any expression.
1616

1717
For example:
1818

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ let sum = function(a, b) {
3333
alert( sum(1, 2) ); // 3
3434
```
3535

36-
As you can, see `(a, b) => a + b` means a function that accepts two arguments named `a` and `b`. Upon the execution, it evaluates the expression `a + b` and returns the result.
36+
As you can see, `(a, b) => a + b` means a function that accepts two arguments named `a` and `b`. Upon the execution, it evaluates the expression `a + b` and returns the result.
3737

3838
- If we have only one argument, then parentheses around parameters can be omitted, making that even shorter.
3939

@@ -86,7 +86,7 @@ Like this:
8686
let sum = (a, b) => { // the curly brace opens a multiline function
8787
let result = a + b;
8888
*!*
89-
return result; // if we use curly braces, then we need an explicit "return"
89+
return result; // if we use curly braces, then we need an explicit "return"
9090
*/!*
9191
};
9292

1-js/04-object-basics/04-object-methods/8-chain-calls/_js.view/solution.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@ let ladder = {
1111
},
1212
showStep: function() {
1313
alert(this.step);
14+
return this;
1415
}
1516
};

1-js/04-object-basics/04-object-methods/8-chain-calls/_js.view/test.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,14 @@ describe('Ladder', function() {
3232
it('down().up().up().up() ', function() {
3333
assert.equal(ladder.down().up().up().up().step, 2);
3434
});
35+
36+
it('showStep() should return this', function() {
37+
assert.equal(ladder.showStep(), ladder);
38+
});
39+
40+
it('up().up().down().showStep().down().showStep()', function () {
41+
assert.equal(ladder.up().up().down().showStep().down().showStep().step, 0)
42+
});
3543

3644
after(function() {
3745
ladder.step = 0;

1-js/04-object-basics/07-optional-chaining/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ That's the expected result. JavaScript works like this. As `user.address` is `un
2525

2626
In many practical cases we'd prefer to get `undefined` instead of an error here (meaning "no street").
2727

28-
...And another example. In the web development, we can get an object that corresponds to a web page element using a special method call, such as `document.querySelector('.elem')`, and it returns `null` when there's no such element.
28+
...and another example. In Web development, we can get an object that corresponds to a web page element using a special method call, such as `document.querySelector('.elem')`, and it returns `null` when there's no such element.
2929

3030
```js run
3131
// document.querySelector('.elem') is null if there's no element

1-js/05-data-types/10-destructuring-assignment/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The two most used data structures in JavaScript are `Object` and `Array`.
55
- Objects allow us to create a single entity that stores data items by key.
66
- Arrays allow us to gather data items into an ordered list.
77

8-
Although, when we pass those to a function, it may need not an object/array as a whole. It may need individual pieces.
8+
Although, when we pass those to a function, it may need not be an object/array as a whole. It may need individual pieces.
99

1010
*Destructuring assignment* is a special syntax that allows us to "unpack" arrays or objects into a bunch of variables, as sometimes that's more convenient.
1111

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,9 @@ So the single `callback` function is used both for reporting errors and passing
196196

197197
## Pyramid of Doom
198198

199-
From the first look, it's a viable way of asynchronous coding. And indeed it is. For one or maybe two nested calls it looks fine.
199+
At first glance, it looks like a viable approach to asynchronous coding. And indeed it is. For one or maybe two nested calls it looks fine.
200200

201-
But for multiple asynchronous actions that follow one after another we'll have code like this:
201+
But for multiple asynchronous actions that follow one after another, we'll have code like this:
202202

203203
```js
204204
loadScript('1.js', function(error, script) {
@@ -229,8 +229,8 @@ loadScript('1.js', function(error, script) {
229229
```
230230

231231
In the code above:
232-
1. We load `1.js`, then if there's no error.
233-
2. We load `2.js`, then if there's no error.
232+
1. We load `1.js`, then if there's no error...
233+
2. We load `2.js`, then if there's no error...
234234
3. We load `3.js`, then if there's no error -- do something else `(*)`.
235235

236236
As calls become more nested, the code becomes deeper and increasingly more difficult to manage, especially if we have real code instead of `...` that may include more loops, conditional statements and so on.
@@ -299,7 +299,7 @@ function step3(error, script) {
299299
}
300300
```
301301

302-
See? It does the same, and there's no deep nesting now because we made every action a separate top-level function.
302+
See? It does the same thing, and there's no deep nesting now because we made every action a separate top-level function.
303303

304304
It works, but the code looks like a torn apart spreadsheet. It's difficult to read, and you probably noticed that one needs to eye-jump between pieces while reading it. That's inconvenient, especially if the reader is not familiar with the code and doesn't know where to eye-jump.
305305

1-js/11-async/03-promise-chaining/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ new Promise(function(resolve, reject) {
120120
});
121121
```
122122

123-
Here the first `.then` shows `1` and returns `new Promise(…)` in the line `(*)`. After one second it resolves, and the result (the argument of `resolve`, here it's `result * 2`) is passed on to handler of the second `.then`. That handler is in the line `(**)`, it shows `2` and does the same thing.
123+
Here the first `.then` shows `1` and returns `new Promise(…)` in the line `(*)`. After one second it resolves, and the result (the argument of `resolve`, here it's `result * 2`) is passed on to the handler of the second `.then`. That handler is in the line `(**)`, it shows `2` and does the same thing.
124124

125125
So the output is the same as in the previous example: 1 -> 2 -> 4, but now with 1 second delay between `alert` calls.
126126

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ An example of use (shows commit authors in console):
376376
377377
for await (const commit of fetchCommits('javascript-tutorial/en.javascript.info')) {
378378
379-
console.log(commit.author.login);
379+
console.log(commit.author.name);
380380
381381
if (++count == 100) { // let's stop at 100 commits
382382
break;

2-ui/2-events/03-event-delegation/article.md

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

22
# Event delegation
33

4-
Capturing and bubbling allow us to implement one of most powerful event handling patterns called *event delegation*.
4+
Capturing and bubbling allow us to implement one of the most powerful event handling patterns called *event delegation*.
55

66
The idea is that if we have a lot of elements handled in a similar way, then instead of assigning a handler to each of them -- we put a single handler on their common ancestor.
77

2-ui/2-events/04-default-browser-action/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ There are two ways to tell the browser we don't want it to act:
1717
- The main way is to use the `event` object. There's a method `event.preventDefault()`.
1818
- If the handler is assigned using `on<event>` (not by `addEventListener`), then returning `false` also works the same.
1919

20-
In this HTML a click on a link doesn't lead to navigation, browser doesn't do anything:
20+
In this HTML, a click on a link doesn't lead to navigation; the browser doesn't do anything:
2121

2222
```html autorun height=60 no-beautify
2323
<a href="/" onclick="return false">Click here</a>
@@ -96,7 +96,7 @@ That's because the browser action is canceled on `mousedown`. The focusing is st
9696

9797
The optional `passive: true` option of `addEventListener` signals the browser that the handler is not going to call `preventDefault()`.
9898

99-
Why that may be needed?
99+
Why might that be needed?
100100

101101
There are some events like `touchmove` on mobile devices (when the user moves their finger across the screen), that cause scrolling by default, but that scrolling can be prevented using `preventDefault()` in the handler.
102102

2-ui/3-event-details/1-mouse-events-basics/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,9 @@ In cases when a single action initiates multiple events, their order is fixed. T
3939
```online
4040
Click the button below and you'll see the events. Try double-click too.
4141
42-
On the teststand below all mouse events are logged, and if there is more than a 1 second delay between them they are separated by a horizontal ruler.
42+
On the teststand below, all mouse events are logged, and if there is more than a 1 second delay between them, they are separated by a horizontal rule.
4343
44-
Also we can see the `button` property that allows to detect the mouse button, it's explained below.
44+
Also, we can see the `button` property that allows us to detect the mouse button; it's explained below.
4545
4646
<input onmousedown="return logMouse(event)" onmouseup="return logMouse(event)" onclick="return logMouse(event)" oncontextmenu="return logMouse(event)" ondblclick="return logMouse(event)" value="Click me with the right or the left mouse button" type="button"> <input onclick="logClear('test')" value="Clear" type="button"> <form id="testform" name="testform"> <textarea style="font-size:12px;height:150px;width:360px;"></textarea></form>
4747
```

2-ui/3-event-details/7-keyboard-events/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ So, `event.code` may match a wrong character for unexpected layout. Same letters
107107

108108
To reliably track layout-dependent characters, `event.key` may be a better way.
109109

110-
On the other hand, `event.code` has the benefit of staying always the same, bound to the physical key location, even if the visitor changes languages. So hotkeys that rely on it work well even in case of a language switch.
110+
On the other hand, `event.code` has the benefit of staying always the same, bound to the physical key location. So hotkeys that rely on it work well even in case of a language switch.
111111

112112
Do we want to handle layout-dependant keys? Then `event.key` is the way to go.
113113

9-regular-expressions/14-regexp-lookahead-lookbehind/article.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@ alert( str.match(/\d+\b(?!€)/g) ); // 2 (the price is not matched)
5959

6060
## Lookbehind
6161

62+
```warn header="Lookbehind browser compatibility"
63+
Please Note: Lookbehind is not supported in non-V8 browsers, such as Safari, Internet Explorer.
64+
```
65+
6266
Lookahead allows to add a condition for "what follows".
6367

6468
Lookbehind is similar, but it looks behind. That is, it allows to match a pattern only if there's something before it.

0 commit comments

Comments
 (0)