Skip to content

Commit 81e06e5

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-c4d1987e
2 parents 65e9233 + c4d1987 commit 81e06e5

File tree

31 files changed

+75
-70
lines changed

31 files changed

+75
-70
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
@@ -5,7 +5,7 @@ This book is a *tutorial*. It aims to help you gradually learn the language. But
55

66
## Specification
77

8-
**The ECMA-262 specification** contains the most in-depth, detailed and formalized information about JavaScript. It defines the language.
8+
[The ECMA-262 specification](https://www.ecma-international.org/publications/standards/Ecma-262.htm) contains the most in-depth, detailed and formalized information about JavaScript. It defines the language.
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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ A [variable](https://en.wikipedia.org/wiki/Variable_(computer_science)) is a "na
1212

1313
To create a variable in JavaScript, use the `let` keyword.
1414

15-
The statement below creates (in other words: *declares* or *defines*) a variable with the name "message":
15+
The statement below creates (in other words: *declares*) a variable with the name "message":
1616

1717
```js
1818
let message;

1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/solution.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ true + false = 1
1414
" -9 " - 5 = -14 // (4)
1515
null + 1 = 1 // (5)
1616
undefined + 1 = NaN // (6)
17+
" \t \n" - 2 = -2 // (7)
1718
```
1819

1920
1. The addition with a string `"" + 1` converts `1` to a string: `"" + 1 = "1"`, and then we have `"1" + 0`, the same rule is applied.
@@ -22,3 +23,4 @@ undefined + 1 = NaN // (6)
2223
4. The subtraction always converts to numbers, so it makes `" -9 "` a number `-9` (ignoring spaces around it).
2324
5. `null` becomes `0` after the numeric conversion.
2425
6. `undefined` becomes `NaN` after the numeric conversion.
26+
7. Space characters, are trimmed off string start and end when a string is converted to a number. Here the whole string consists of space characters, such as `\t`, `\n` and a "regular" space between them. So, similarly to an empty string, it becomes `0`.

1-js/02-first-steps/06-type-conversions/1-primitive-conversions-questions/task.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ true + false
2121
" -9 " - 5
2222
null + 1
2323
undefined + 1
24+
" \t \n" - 2
2425
```
2526

2627
Think well, write down and then compare with the answer.

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

Lines changed: 6 additions & 6 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-
## ToString
13+
## To String
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-
## ToNumber
33+
## To Number
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-
## ToBoolean
97+
## To Boolean
9898

9999
Boolean conversion is the simplest one.
100100

@@ -129,9 +129,9 @@ alert( Boolean(" ") ); // spaces, also true (any non-empty string is true)
129129
130130
The three most widely used type conversions are to string, to number, and to boolean.
131131
132-
**`ToString`** -- Occurs when we output something. Can be performed with `String(value)`. The conversion to string is usually obvious for primitive values.
132+
**`To String`** -- Occurs when we output something. Can be performed with `String(value)`. The conversion to string is usually obvious for primitive values.
133133
134-
**`ToNumber`** -- Occurs in math operations. Can be performed with `Number(value)`.
134+
**`To Number`** -- Occurs in math operations. Can be performed with `Number(value)`.
135135
136136
The conversion follows the rules:
137137
@@ -142,7 +142,7 @@ The conversion follows the rules:
142142
|<code>true&nbsp;/&nbsp;false</code> | `1 / 0` |
143143
| `string` | The string is read "as is", whitespaces from both sides are ignored. An empty string becomes `0`. An error gives `NaN`. |
144144
145-
**`ToBoolean`** -- Occurs in logical operations. Can be performed with `Boolean(value)`.
145+
**`To Boolean`** -- Occurs in logical operations. Can be performed with `Boolean(value)`.
146146
147147
Follows the rules:
148148

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Before we move on, let's grasp some common terminology.
2626
alert( y - x ); // 2, binary minus subtracts values
2727
```
2828

29-
Formally, we're talking about two different operators here: the unary negation (single operand: reverses the sign) and the binary subtraction (two operands: subtracts).
29+
Formally, in the examples above we have two different operators that share the same symbol: the negation operator, a unary operator that reverses the sign, and the subtraction operator, a binary operator that subtracts one number from another.
3030

3131
## String concatenation, binary +
3232

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ Let's examine the `for` statement part-by-part:
108108
|-------|----------|----------------------------------------------------------------------------|
109109
| begin | `i = 0` | Executes once upon entering the loop. |
110110
| condition | `i < 3`| Checked before every loop iteration. If false, the loop stops. |
111-
| step| `i++` | Executes after the body on each iteration but before the condition check. |
112111
| body | `alert(i)`| Runs again and again while the condition is truthy. |
112+
| step| `i++` | Executes after the body on each iteration. |
113113

114114
The general loop algorithm works like this:
115115

@@ -300,7 +300,7 @@ This is just another reason not to use the question mark operator `?` instead of
300300

301301
Sometimes we need to break out from multiple nested loops at once.
302302

303-
For example, in the code below we loop over `i` and `j`, prompting for the coordinates `(i, j)` from `(0,0)` to `(3,3)`:
303+
For example, in the code below we loop over `i` and `j`, prompting for the coordinates `(i, j)` from `(0,0)` to `(2,2)`:
304304

305305
```js run no-beautify
306306
for (let i = 0; i < 3; i++) {

1-js/02-first-steps/16-javascript-specials/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@ Conditional
149149
: The only operator with three parameters: `cond ? resultA : resultB`. If `cond` is truthy, returns `resultA`, otherwise `resultB`.
150150

151151
Logical operators
152-
: Logical AND `&&` and OR `||` perform short-circuit evaluation and then return the value where it stopped. Logical NOT `!` converts the operand to boolean type and returns the inverse value.
152+
: Logical AND `&&` and OR `||` perform short-circuit evaluation and then return the value where it stopped (not necessary `true`/`false`). Logical NOT `!` converts the operand to boolean type and returns the inverse value.
153153

154154
Comparisons
155155
: Equality check `==` for values of different types converts them to a number (except `null` and `undefined` that equal each other and nothing else), so these are equal:

1-js/03-code-quality/03-comments/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,6 @@ Good comments allow us to maintain the code well, come back to it after a delay
175175
**Avoid comments:**
176176

177177
- That tell "how code works" and "what it does".
178-
- Put them only if it's impossible to make the code so simple and self-descriptive that it doesn't require those.
178+
- Put them in only if it's impossible to make the code so simple and self-descriptive that it doesn't require them.
179179

180180
Comments are also used for auto-documenting tools like JSDoc3: they read them and generate HTML-docs (or docs in another format).

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ Here Babel comes to the rescue.
1919

2020
Actually, there are two parts in Babel:
2121

22-
1. First, the transpiler program, which rewrites the code. The developer runs it on their own computer. It rewrites the code into the older standard. And then the code is delivered to the website for users. Modern project build system like [webpack](http://webpack.github.io/) provide means to run transpiler automatically on every code change, so that very easy to integrate into development process.
22+
1. First, the transpiler program, which rewrites the code. The developer runs it on their own computer. It rewrites the code into the older standard. And then the code is delivered to the website for users. Modern project build systems like [webpack](http://webpack.github.io/) provide means to run transpiler automatically on every code change, so that very easy to integrate into development process.
2323

2424
2. Second, the polyfill.
2525

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,10 +148,10 @@ function BigUser() {
148148

149149
this.name = "John";
150150

151-
return { name: "Godzilla" }; // <-- returns an object
151+
return { name: "Godzilla" }; // <-- returns this object
152152
}
153153

154-
alert( new BigUser().name ); // Godzilla, got that object ^^
154+
alert( new BigUser().name ); // Godzilla, got that object
155155
```
156156

157157
And here's an example with an empty `return` (or we could place a primitive after it, doesn't matter):
@@ -161,10 +161,7 @@ function SmallUser() {
161161

162162
this.name = "John";
163163

164-
return; // finishes the execution, returns this
165-
166-
// ...
167-
164+
return; // <-- returns this
168165
}
169166

170167
alert( new SmallUser().name ); // John
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
function Calculator() {
22

3-
let methods = {
3+
this.methods = {
44
"-": (a, b) => a - b,
55
"+": (a, b) => a + b
66
};
@@ -12,14 +12,14 @@ function Calculator() {
1212
op = split[1],
1313
b = +split[2]
1414

15-
if (!methods[op] || isNaN(a) || isNaN(b)) {
15+
if (!this.methods[op] || isNaN(a) || isNaN(b)) {
1616
return NaN;
1717
}
1818

19-
return methods[op](a, b);
19+
return this.methods[op](a, b);
2020
}
2121

2222
this.addMethod = function(name, func) {
23-
methods[name] = func;
23+
this.methods[name] = func;
2424
};
2525
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11

2-
- Please note how methods are stored. They are simply added to the internal object.
2+
- Please note how methods are stored. They are simply added to `this.methods` property.
33
- All tests and numeric conversions are done in the `calculate` method. In future it may be extended to support more complex expressions.
4+
5+
[js src="_js/solution.js"]

1-js/05-data-types/05-array-methods/6-calculator-extendable/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,6 @@ The task consists of two parts.
3131
alert( result ); // 8
3232
```
3333

34-
- No brackets or complex expressions in this task.
34+
- No parentheses or complex expressions in this task.
3535
- The numbers and the operator are delimited with exactly one space.
3636
- There may be error handling if you'd like to add it.

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ The method [arr.slice](mdn:js/Array/slice) is much simpler than similar-looking
119119
The syntax is:
120120

121121
```js
122-
arr.slice(start, end)
122+
arr.slice([start], [end])
123123
```
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.
@@ -136,6 +136,8 @@ alert( arr.slice(1, 3) ); // e,s (copy from 1 to 3)
136136
alert( arr.slice(-2) ); // s,t (copy from -2 till the end)
137137
```
138138

139+
We can also call it without arguments: `arr.slice()` creates a copy of `arr`. That's often used to obtain a copy for further transformations that should not affect the original array.
140+
139141
### concat
140142

141143
The method [arr.concat](mdn:js/Array/concat) creates a new array that includes values from other arrays and additional items.

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ We can avoid it by switching to `WeakMap` instead:
155155

156156
```js
157157
// 📁 visitsCount.js
158-
let visitsCountMap = new WeakMap(); // map: user => visits count
158+
let visitsCountMap = new WeakMap(); // weakmap: user => visits count
159159

160160
// increase the visits count
161161
function countUser(user) {
@@ -164,7 +164,7 @@ function countUser(user) {
164164
}
165165
```
166166

167-
Now we don't have to clean `visitsCountMap`. After `john` object becomes unreachable by all means except as a key of `WeakMap`, it gets removed from memory, along with the information by that key from `WeakMap`.
167+
Now we don't have to clean `visitsCountMap`. After `john` object becomes unreachable by all means except as a key of `WeakMap`, it gets removed from memory, along with the information by that key from `WeakMap`.
168168

169169
## Use case: caching
170170

@@ -284,6 +284,6 @@ The most notable limitation of `WeakMap` and `WeakSet` is the absence of iterati
284284

285285
`WeakSet` is `Set`-like collection that stores only objects and removes them once they become inaccessible by other means.
286286

287-
Both of them do not support methods and properties that refer to all keys or their count. Only individial operations are allowed.
287+
Both of them do not support methods and properties that refer to all keys or their count. Only individual operations are allowed.
288288

289289
`WeakMap` and `WeakSet` are used as "secondary" data structures in addition to the "main" object storage. Once the object is removed from the main storage, if it is only found as the key of `WeakMap` or in a `WeakSet`, it will be cleaned up automatically.

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ The problem is that JavaScript treats `{...}` in the main code flow (not inside
356356
}
357357
```
358358

359-
So here JavaScript assumes that we have a code block, but why there's an error. We have destructuring instead.
359+
So here JavaScript assumes that we have a code block, that's why there's an error. We have destructuring instead.
360360

361361
To show JavaScript that it's not a code block, we can wrap the expression in parentheses `(...)`:
362362

1-js/05-data-types/12-json/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -393,7 +393,7 @@ alert( JSON.stringify(meetup) );
393393
*/
394394
```
395395

396-
As we can see, `toJSON` is used both for the direct call `JSON.stringify(room)` and when `room` is nested is another encoded object.
396+
As we can see, `toJSON` is used both for the direct call `JSON.stringify(room)` and when `room` is nested in another encoded object.
397397

398398

399399
## JSON.parse

1-js/06-advanced-functions/01-recursion/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ function pow(x, n) {
9696
9797
The maximal number of nested calls (including the first one) is called *recursion depth*. In our case, it will be exactly `n`.
9898
99-
The maximal recursion depth is limited by JavaScript engine. We can make sure about 10000, some engines allow more, but 100000 is probably out of limit for the majority of them. There are automatic optimizations that help alleviate this ("tail calls optimizations"), but they are not yet supported everywhere and work only in simple cases.
99+
The maximal recursion depth is limited by JavaScript engine. We can rely on it being 10000, some engines allow more, but 100000 is probably out of limit for the majority of them. There are automatic optimizations that help alleviate this ("tail calls optimizations"), but they are not yet supported everywhere and work only in simple cases.
100100
101101
That limits the application of recursion, but it still remains very wide. There are many tasks where recursive way of thinking gives simpler code, easier to maintain.
102102

1-js/06-advanced-functions/02-rest-parameters-spread-operator/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ alert( sum(1, 2, 3, 4, 5) );
2525

2626
There will be no error because of "excessive" arguments. But of course in the result only the first two will be counted.
2727

28-
The rest parameters can be mentioned in a function definition with three dots `...`. They literally mean "gather the remaining parameters into an array".
28+
The rest of the parameters can be included in the function definition by using three dots `...` followed by the name of the array that will contain them. The dots literally mean "gather the remaining parameters into an array".
2929

3030
For instance, to gather all arguments into array `args`:
3131

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -313,7 +313,7 @@ Hopefully, the situation with outer variables is clear now. For most situations
313313

314314
## Environments in detail
315315

316-
Here's what's going on in the `makeCounter` example step-by-step, follow it to make sure that you know things in the very detail.
316+
Here's what's going on in the `makeCounter` example step-by-step, follow it to make sure that you understand how it works in detail.
317317

318318
Please note the additional `[[Environment]]` property is covered here. We didn't mention it before for simplicity.
319319

1-js/06-advanced-functions/05-global-object/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The global object provides variables and functions that are available anywhere.
55

66
In a browser it is named `window`, for Node.js it is `global`, for other environments it may have another name.
77

8-
Recently, `globalThis` was added to the language, as a standartized name for a global object, that should be supported across all environments. In some browsers, namely non-Chromium Edge, `globalThis` is not yet supported, but can be easily polyfilled.
8+
Recently, `globalThis` was added to the language, as a standardized name for a global object, that should be supported across all environments. In some browsers, namely non-Chromium Edge, `globalThis` is not yet supported, but can be easily polyfilled.
99

1010
We'll use `window` here, assuming that our environment is a browser. If your script may run in other environments, it's better to use `globalThis` instead.
1111

1-js/06-advanced-functions/06-function-object/article.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,6 +347,7 @@ If the function is declared as a Function Expression (not in the main code flow)
347347

348348
Also, functions may carry additional properties. Many well-known JavaScript libraries make great use of this feature.
349349

350-
They create a "main" function and attach many other "helper" functions to it. For instance, the [jQuery](https://jquery.com) library creates a function named `$`. The [lodash](https://lodash.com) library creates a function `_`. And then adds `_.clone`, `_.keyBy` and other properties to (see the [docs](https://lodash.com/docs) when you want learn more about them). Actually, they do it to lessen their pollution of the global space, so that a single library gives only one global variable. That reduces the possibility of naming conflicts.
350+
They create a "main" function and attach many other "helper" functions to it. For instance, the [jQuery](https://jquery.com) library creates a function named `$`. The [lodash](https://lodash.com) library creates a function `_`, and then adds `_.clone`, `_.keyBy` and other properties to it (see the [docs](https://lodash.com/docs) when you want learn more about them). Actually, they do it to lessen their pollution of the global space, so that a single library gives only one global variable. That reduces the possibility of naming conflicts.
351+
351352

352353
So, a function can do a useful job by itself and also carry a bunch of other functionality in properties.

1-js/06-advanced-functions/09-call-apply-decorators/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ From an outside code, the wrapped `slow` function still does the same. It just g
5858
To summarize, there are several benefits of using a separate `cachingDecorator` instead of altering the code of `slow` itself:
5959

6060
- The `cachingDecorator` is reusable. We can apply it to another function.
61-
- The caching logic is separate, it did not increase the complexity of `slow` itself (if there were any).
61+
- The caching logic is separate, it did not increase the complexity of `slow` itself (if there was any).
6262
- We can combine multiple decorators if needed (other decorators will follow).
6363

6464

1-js/09-classes/03-static-properties-methods/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ class Article {
9090

9191
let article = Article.createTodays();
9292

93-
alert( article.title ); // Todays digest
93+
alert( article.title ); // Today's digest
9494
```
9595

9696
Now every time we need to create a today's digest, we can call `Article.createTodays()`. Once again, that's not a method of an article, but a method of the whole class.

2-ui/1-document/03-dom-navigation/3-navigation-links-which-null/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
1. Yes, true. The element `elem.lastChild` is always the last one, it has no `nextSibling`.
2-
2. No, wrong, because `elem.children[0]` is the first child *among elements*. But there may exist non-element nodes before it. So `previousSibling` may be a text node. Also, if there are no children, then trying to access `elem.children[0]`
2+
2. No, wrong, because `elem.children[0]` is the first child *among elements*. But there may exist non-element nodes before it. So `previousSibling` may be a text node.
33

44
Please note: for both cases if there are no children, then there will be an error.
55

0 commit comments

Comments
 (0)