Skip to content

Commit abd81af

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-3dd8ca09
2 parents 81e06e5 + 3dd8ca0 commit abd81af

File tree

122 files changed

+2681
-2376
lines changed

Some content is hidden

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

122 files changed

+2681
-2376
lines changed

1-js/01-getting-started/2-manuals-specifications/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ This book is a *tutorial*. It aims to help you gradually learn the language. But
99

1010
But being that formalized, it's difficult to understand at first. So if you need the most trustworthy source of information about the language details, the specification is the right place. But it's not for everyday use.
1111

12-
The latest draft is at <https://tc39.es/ecma262/>.
12+
A new specification version is released every year. In-between these releases, the latest specification draft is at <https://tc39.es/ecma262/>.
1313

1414
To read about new bleeding-edge features, including those that are "almost standard" (so-called "stage 3"), see proposals at <https://github.com/tc39/proposals>.
1515

1-js/02-first-steps/06-type-conversions/article.md

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ There are also cases when we need to explicitly convert a value to the expected
1010
In this chapter, we won't cover objects. Instead, we'll study primitives first. Later, after we learn about objects, we'll see how object conversion works in the chapter <info:object-toprimitive>.
1111
```
1212

13-
## To String
13+
## String Conversion
1414

1515
String conversion happens when we need the string form of a value.
1616

@@ -30,7 +30,7 @@ alert(typeof value); // string
3030

3131
String conversion is mostly obvious. A `false` becomes `"false"`, `null` becomes `"null"`, etc.
3232

33-
## To Number
33+
## Numeric Conversion
3434

3535
Numeric conversion happens in mathematical functions and expressions automatically.
3636

@@ -94,7 +94,7 @@ alert( '1' + 2 ); // '12' (string to the left)
9494
This only happens when at least one of the arguments is a string. Otherwise, values are converted to numbers.
9595
````
9696

97-
## To Boolean
97+
## Boolean Conversion
9898

9999
Boolean conversion is the simplest one.
100100

@@ -124,14 +124,13 @@ alert( Boolean(" ") ); // spaces, also true (any non-empty string is true)
124124
```
125125
````
126126
127-
128127
## Summary
129128
130129
The three most widely used type conversions are to string, to number, and to boolean.
131130
132-
**`To String`** -- Occurs when we output something. Can be performed with `String(value)`. The conversion to string is usually obvious for primitive values.
131+
**`String Conversion`** -- Occurs when we output something. Can be performed with `String(value)`. The conversion to string is usually obvious for primitive values.
133132
134-
**`To Number`** -- Occurs in math operations. Can be performed with `Number(value)`.
133+
**`Numeric Conversion`** -- Occurs in math operations. Can be performed with `Number(value)`.
135134
136135
The conversion follows the rules:
137136
@@ -142,7 +141,7 @@ The conversion follows the rules:
142141
|<code>true&nbsp;/&nbsp;false</code> | `1 / 0` |
143142
| `string` | The string is read "as is", whitespaces from both sides are ignored. An empty string becomes `0`. An error gives `NaN`. |
144143
145-
**`To Boolean`** -- Occurs in logical operations. Can be performed with `Boolean(value)`.
144+
**`Boolean Conversion`** -- Occurs in logical operations. Can be performed with `Boolean(value)`.
146145
147146
Follows the rules:
148147
Lines changed: 1 addition & 1 deletion
Loading

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

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ It's common that an object method needs to access the information stored in the
9898

9999
For instance, the code inside `user.sayHi()` may need the name of the `user`.
100100

101-
**To access the object, a method can use the `this` keyword.**
101+
**To access the object, a method can use `this` keyword.**
102102

103103
The value of `this` is the object "before dot", the one used to call the method.
104104

@@ -167,9 +167,9 @@ If we used `this.name` instead of `user.name` inside the `alert`, then the code
167167

168168
## "this" is not bound
169169

170-
In JavaScript, "this" keyword behaves unlike most other programming languages. It can be used in any function.
170+
In JavaScript, keyword `this` behaves unlike most other programming languages. It can be used in any function.
171171

172-
There's no syntax error in the code like that:
172+
There's no syntax error in the following example:
173173

174174
```js
175175
function sayHi() {
@@ -220,13 +220,13 @@ In this case `this` is `undefined` in strict mode. If we try to access `this.nam
220220

221221
In non-strict mode the value of `this` in such case will be the *global object* (`window` in a browser, we'll get to it later in the chapter [](info:global-object)). This is a historical behavior that `"use strict"` fixes.
222222

223-
Usually such call is an programming error. If there's `this` inside a function, it expects to be called in an object context.
223+
Usually such call is a programming error. If there's `this` inside a function, it expects to be called in an object context.
224224
````
225225
226226
```smart header="The consequences of unbound `this`"
227227
If you come from another programming language, then you are probably used to the idea of a "bound `this`", where methods defined in an object always have `this` referencing that object.
228228
229-
In JavaScript `this` is "free", its value is evaluated at call-time and does not depend on where the method was declared, but rather on what's the object "before the dot".
229+
In JavaScript `this` is "free", its value is evaluated at call-time and does not depend on where the method was declared, but rather on what object is "before the dot".
230230
231231
The concept of run-time evaluated `this` has both pluses and minuses. On the one hand, a function can be reused for different objects. On the other hand, greater flexibility opens a place for mistakes.
232232

1-js/04-object-basics/06-constructor-new/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ alert(user.name); // Jack
2727
alert(user.isAdmin); // false
2828
```
2929

30-
When a function is executed as `new User(...)`, it does the following steps:
30+
When a function is executed with `new`, it does the following steps:
3131

3232
1. A new empty object is created and assigned to `this`.
3333
2. The function body executes. Usually it modifies `this`, adds new properties to it.
@@ -51,7 +51,7 @@ function User(name) {
5151
}
5252
```
5353

54-
So the result of `new User("Jack")` is the same object as:
54+
So `let user = new User("Jack")` gives the same result as:
5555

5656
```js
5757
let user = {

1-js/05-data-types/01-primitives-methods/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ The solution looks a little bit awkward, but here it is:
5050

5151
The "object wrappers" are different for each primitive type and are called: `String`, `Number`, `Boolean` and `Symbol`. Thus, they provide different sets of methods.
5252

53-
For instance, there exists a method [str.toUpperCase()](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase) that returns a capitalized string.
53+
For instance, there exists a string method [str.toUpperCase()](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/String/toUpperCase) that returns a capitalized `str`.
5454

5555
Here's how it works:
5656

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ let guestList = "Guests: // Error: Unexpected token ILLEGAL
5050

5151
Single and double quotes come from ancient times of language creation when the need for multiline strings was not taken into account. Backticks appeared much later and thus are more versatile.
5252

53-
Backticks also allow us to specify a "template function" before the first backtick. The syntax is: <code>func&#96;string&#96;</code>. The function `func` is called automatically, receives the string and embedded expressions and can process them. You can read more about it in the [docs](mdn:/JavaScript/Reference/Template_literals#Tagged_template_literals). This is called "tagged templates". This feature makes it easier to wrap strings into custom templating or other functionality, but it is rarely used.
53+
Backticks also allow us to specify a "template function" before the first backtick. The syntax is: <code>func&#96;string&#96;</code>. The function `func` is called automatically, receives the string and embedded expressions and can process them. You can read more about it in the [docs](mdn:/JavaScript/Reference/Template_literals#Tagged_templates). This is called "tagged templates". This feature makes it easier to wrap strings into custom templating or other functionality, but it is rarely used.
5454

5555
## Special characters
5656

1-js/05-data-types/05-array-methods/article.md

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -655,31 +655,37 @@ arr.map(func, thisArg);
655655

656656
The value of `thisArg` parameter becomes `this` for `func`.
657657

658-
For instance, here we use an object method as a filter and `thisArg` helps with that:
658+
For example, here we use a method of `army` object as a filter, and `thisArg` passes the context:
659659

660660
```js run
661-
let user = {
662-
age: 18,
663-
younger(otherUser) {
664-
return otherUser.age < this.age;
661+
let army = {
662+
minAge: 18,
663+
maxAge: 27,
664+
canJoin(user) {
665+
return user.age >= this.minAge && user.age < this.maxAge;
665666
}
666667
};
667668

668669
let users = [
669-
{age: 12},
670670
{age: 16},
671-
{age: 32}
671+
{age: 20},
672+
{age: 23},
673+
{age: 30}
672674
];
673675

674676
*!*
675-
// find all users younger than user
676-
let youngerUsers = users.filter(user.younger, user);
677+
// find users, for who army.canJoin returns true
678+
let soldiers = users.filter(army.canJoin, army);
677679
*/!*
678680

679-
alert(youngerUsers.length); // 2
681+
alert(soldiers.length); // 2
682+
alert(soldiers[0].age); // 20
683+
alert(soldiers[1].age); // 23
680684
```
681685

682-
In the call above, we use `user.younger` as a filter and also provide `user` as the context for it. If we didn't provide the context, `users.filter(user.younger)` would call `user.younger` as a standalone function, with `this=undefined`. That would mean an instant error.
686+
If in the example above we used `users.filter(army.canJoin)`, then `army.canJoin` would be called as a standalone function, with `this=undefined`, thus leading to an instant error.
687+
688+
A call to `users.filter(army.canJoin, army)` can be replaced with `users.filter(user => army.canJoin(user))`, that does the same. The former is used more often, as it's a bit easier to understand for most people.
683689

684690
## Summary
685691

1-js/05-data-types/08-weakmap-weakset/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ countUser(john);
147147
john = null;
148148
```
149149

150-
Now `john` object should be garbage collected, but remains is memory, as it's a key in `visitsCountMap`.
150+
Now `john` object should be garbage collected, but remains in memory, as it's a key in `visitsCountMap`.
151151

152152
We need to clean `visitsCountMap` when we remove users, otherwise it will grow in memory indefinitely. Such cleaning can become a tedious task in complex architectures.
153153

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ alert(item1); // Cake
403403
alert(item2); // Donut
404404
```
405405
406-
The whole `options` object except `extra` that was not mentioned, is assigned to corresponding variables:
406+
All properties of `options` object except `extra` that is absent in the left part, are assigned to corresponding variables:
407407
408408
![](destructuring-complex.svg)
409409

1-js/06-advanced-functions/08-settimeout-setinterval/1-output-numbers-100ms/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function printNumbers(from, to) {
1818
printNumbers(5, 10);
1919
```
2020

21-
Using recursive `setTimeout`:
21+
Using nested `setTimeout`:
2222

2323

2424
```js run

1-js/06-advanced-functions/08-settimeout-setinterval/1-output-numbers-100ms/task.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,4 @@ Write a function `printNumbers(from, to)` that outputs a number every second, st
99
Make two variants of the solution.
1010

1111
1. Using `setInterval`.
12-
2. Using recursive `setTimeout`.
13-
12+
2. Using nested `setTimeout`.

0 commit comments

Comments
 (0)