Skip to content

Commit 05475a3

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-0e4f5e42
2 parents a1254b7 + 0e4f5e4 commit 05475a3

File tree

22 files changed

+55
-45
lines changed

22 files changed

+55
-45
lines changed

Diff for: 1-js/01-getting-started/3-code-editors/article.md

+1
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ In practice, lightweight editors may have a lot of plugins including directory-l
3232
The following options deserve your attention:
3333

3434
- [Atom](https://atom.io/) (cross-platform, free).
35+
- [Visual Studio Code](https://code.visualstudio.com/) (cross-platform, free).
3536
- [Sublime Text](http://www.sublimetext.com) (cross-platform, shareware).
3637
- [Notepad++](https://notepad-plus-plus.org/) (Windows, free).
3738
- [Vim](http://www.vim.org/) and [Emacs](https://www.gnu.org/software/emacs/) are also cool if you know how to use them.

Diff for: 1-js/02-first-steps/01-hello-world/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ Comments before and after scripts.
6060
//--></script>
6161
```
6262

63-
This trick isn't used in modern JavaScript. These comments hid JavaScript code from old browsers that didn't know how to process the `<script>` tag. Since browsers released in the last 15 years don't have this issue, this kind of comment can help you identify really old code.
63+
This trick isn't used in modern JavaScript. These comments hide JavaScript code from old browsers that didn't know how to process the `<script>` tag. Since browsers released in the last 15 years don't have this issue, this kind of comment can help you identify really old code.
6464

6565

6666
## External scripts

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ To declare a constant (unchanging) variable, use `const` instead of `let`:
237237
const myBirthday = '18.04.1982';
238238
```
239239
240-
Variables declared using `const` are called "constants". They cannot be changed. An attempt to do so would cause an error:
240+
Variables declared using `const` are called "constants". They cannot be reassigned. An attempt to do so would cause an error:
241241
242242
```js run
243243
const myBirthday = '18.04.1982';

Diff for: 1-js/02-first-steps/12-while-for/7-list-primes/solution.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,4 @@ for (let i = 2; i <= n; i++) { // for each i...
2626
}
2727
```
2828

29-
There's a lot of space to opimize it. For instance, we could look for the divisors from `2` to square root of `i`. But anyway, if we want to be really efficient for large intervals, we need to change the approach and rely on advanced maths and complex algorithms like [Quadratic sieve](https://en.wikipedia.org/wiki/Quadratic_sieve), [General number field sieve](https://en.wikipedia.org/wiki/General_number_field_sieve) etc.
29+
There's a lot of space to optimize it. For instance, we could look for the divisors from `2` to square root of `i`. But anyway, if we want to be really efficient for large intervals, we need to change the approach and rely on advanced maths and complex algorithms like [Quadratic sieve](https://en.wikipedia.org/wiki/Quadratic_sieve), [General number field sieve](https://en.wikipedia.org/wiki/General_number_field_sieve) etc.

Diff for: 1-js/02-first-steps/15-function-expressions-arrows/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ Please note that the last line does not run the function, because there are no p
4040

4141
In JavaScript, a function is a value, so we can deal with it as a value. The code above shows its string representation, which is the source code.
4242

43-
Surely, a function is a special values, in the sense that we can call it like `sayHi()`.
43+
Surely, a function is a special value, in the sense that we can call it like `sayHi()`.
4444

4545
But it's still a value. So we can work with it like with other kinds of values.
4646

Diff for: 1-js/04-object-basics/01-object/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -711,7 +711,7 @@ alert(clone.sizes.width); // 51, see the result from the other one
711711
712712
To fix that, we should use the cloning loop that examines each value of `user[key]` and, if it's an object, then replicate its structure as well. That is called a "deep cloning".
713713
714-
There's a standard algorithm for deep cloning that handles the case above and more complex cases, called the [Structured cloning algorithm](http://w3c.github.io/html/infrastructure.html#safe-passing-of-structured-data). In order not to reinvent the wheel, we can use a working implementation of it from the JavaScript library [lodash](https://lodash.com), the method is called [_.cloneDeep(obj)](https://lodash.com/docs#cloneDeep).
714+
There's a standard algorithm for deep cloning that handles the case above and more complex cases, called the [Structured cloning algorithm](https://html.spec.whatwg.org/multipage/structured-data.html#safe-passing-of-structured-data). In order not to reinvent the wheel, we can use a working implementation of it from the JavaScript library [lodash](https://lodash.com), the method is called [_.cloneDeep(obj)](https://lodash.com/docs#cloneDeep).
715715
716716
717717

Diff for: 1-js/04-object-basics/04-object-methods/article.md

+1-1
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 `this` keyword.**
101+
**To access the object, a method can use the `this` keyword.**
102102

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

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ To write big numbers:
417417
For different numeral systems:
418418

419419
- Can write numbers directly in hex (`0x`), octal (`0o`) and binary (`0b`) systems
420-
- `parseInt(str, base)` parses an integer from any numeral system with base: `2 ≤ base ≤ 36`.
420+
- `parseInt(str, base)` parses the string `str` into an integer in numeral system with given `base`, `2 ≤ base ≤ 36`.
421421
- `num.toString(base)` converts a number to a string in the numeral system with the given `base`.
422422

423423
For converting values like `12pt` and `100px` to a number:

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

+1-1
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_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.
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. This is called "tagged templates". This feature makes it easier to implement custom templating, but is rarely used in practice. You can read more about it in the [manual](mdn:/JavaScript/Reference/Template_literals#Tagged_templates).
5454

5555
## Special characters
5656

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ alert( arr.concat([3, 4], [5, 6])); // 1,2,3,4,5,6
169169
alert( arr.concat([3, 4], 5, 6)); // 1,2,3,4,5,6
170170
```
171171

172-
Normally, it only copies elements from arrays. Other objects, even if they look like arrays, added as a whole:
172+
Normally, it only copies elements from arrays. Other objects, even if they look like arrays, are added as a whole:
173173

174174
```js run
175175
let arr = [1, 2];
@@ -183,7 +183,7 @@ alert( arr.concat(arrayLike) ); // 1,2,[object Object]
183183
//[1, 2, arrayLike]
184184
```
185185

186-
...But if an array-like object has a special property `Symbol.isConcatSpreadable` property, the it's treated as array by `concat`: its elements are added instead:
186+
...But if an array-like object has a special `Symbol.isConcatSpreadable` property, then it's treated as an array by `concat`: its elements are added instead:
187187

188188
```js run
189189
let arr = [1, 2];

Diff for: 1-js/08-prototypes/02-function-prototype/4-new-object-same-constructor/solution.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ alert( user2.name ); // Pete (worked!)
1515

1616
It worked, because `User.prototype.constructor == User`.
1717

18-
..But if someone, so to say, overwrites `User.prototype` and forgets to recreate `"constructor"`, then it would fail.
18+
..But if someone, so to speak, overwrites `User.prototype` and forgets to recreate `"constructor"`, then it would fail.
1919

2020
For instance:
2121

Diff for: 1-js/08-prototypes/04-prototype-methods/article.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ Why so?
7272
That's for historical reasons.
7373

7474
- The `"prototype"` property of a constructor function works since very ancient times.
75-
- Later, in the year 2012: `Object.create` appeared in the standard. It allowed to create objects with the given prototype, but did not allow to get/set it. So browsers implemented non-standard `__proto__` accessor that allowed to get/set a prototype at any time.
76-
- Later, in the year 2015: `Object.setPrototypeOf` and `Object.getPrototypeOf` were added to the standard, to perform the same functionality as `__proto__`. As `__proto__` was de-facto implemented everywhere, it was kind-of deprecated and made its way to the Annex B of the standard, that is optional for non-browser environments.
75+
- Later, in the year 2012: `Object.create` appeared in the standard. It gave the ability to create objects with a given prototype, but did not provide the ability to get/set it. So browsers implemented the non-standard `__proto__` accessor that allowed the user to get/set a prototype at any time.
76+
- Later, in the year 2015: `Object.setPrototypeOf` and `Object.getPrototypeOf` were added to the standard, to perform the same functionality as `__proto__`. As `__proto__` was de-facto implemented everywhere, it was kind-of deprecated and made its way to the Annex B of the standard, that is: optional for non-browser environments.
7777

7878
As of now we have all these ways at our disposal.
7979

@@ -190,7 +190,7 @@ Also, `Object.create` provides an easy way to shallow-copy an object with all de
190190
let clone = Object.create(Object.getPrototypeOf(obj), Object.getOwnPropertyDescriptors(obj));
191191
```
192192

193-
We also made it clear that `__proto__` is a getter/setter for `[[Prototype]]` and resides in `Object.prototype`, just as other methods.
193+
We also made it clear that `__proto__` is a getter/setter for `[[Prototype]]` and resides in `Object.prototype`, just like other methods.
194194

195195
We can create an object without a prototype by `Object.create(null)`. Such objects are used as "pure dictionaries", they have no issues with `"__proto__"` as the key.
196196

Diff for: 1-js/09-classes/01-class/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ class User {
320320
new User().sayHi();
321321
```
322322

323-
The property `name` is not placed into `User.prototype`. Instead, it is created by `new` before calling constructor, it's the property of the object itself.
323+
The property `name` is not placed into `User.prototype`. Instead, it is created by `new` before calling the constructor, it's a property of the object itself.
324324

325325
## Summary
326326

Diff for: 1-js/09-classes/02-class-inheritance/3-class-extend-object/task.md

-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ let rabbit = new Rabbit("Rab");
1919

2020
*!*
2121
// hasOwnProperty method is from Object.prototype
22-
// rabbit.__proto__ === Object.prototype
2322
alert( rabbit.hasOwnProperty('name') ); // true
2423
*/!*
2524
```

Diff for: 1-js/09-classes/02-class-inheritance/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ The short answer is: constructors in inheriting classes must call `super(...)`,
261261

262262
Of course, there's an explanation. Let's get into details, so you'll really understand what's going on.
263263

264-
In JavaScript, there's a distinction between a "constructor function of an inheriting class" and all others. In an inheriting class, the corresponding constructor function is labelled with a special internal property `[[ConstructorKind]]:"derived"`.
264+
In JavaScript, there's a distinction between a "constructor function of an inheriting class" and all others. In an inheriting class, the corresponding constructor function is labeled with a special internal property `[[ConstructorKind]]:"derived"`.
265265

266266
The difference is:
267267

@@ -312,7 +312,7 @@ If you're reading the tutorial for the first time - this section may be skipped.
312312
It's about the internal mechanisms behind inheritance and `super`.
313313
```
314314

315-
Let's get a little deeper under the hood of `super`. We'll see some interesting things by the way.
315+
Let's get a little deeper under the hood of `super`. We'll see some interesting things along the way.
316316

317317
First to say, from all that we've learned till now, it's impossible for `super` to work at all!
318318

Diff for: 1-js/09-classes/06-instanceof/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ alert( arr instanceof Array ); // true
4444
alert( arr instanceof Object ); // true
4545
```
4646

47-
Please note that `arr` also belongs to the `Object` class. That's because `Array` prototypally inherits from `Object`.
47+
Please note that `arr` also belongs to the `Object` class. That's because `Array` prototypically inherits from `Object`.
4848

4949
Normally, `instanceof` operator examines the prototype chain for the check. We can also set a custom logic in the static method `Symbol.hasInstance`.
5050

Diff for: 1-js/09-classes/07-mixins/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ And `eventMixin` mixin makes it easy to add such behavior to as many classes as
201201

202202
*Mixin* -- is a generic object-oriented programming term: a class that contains methods for other classes.
203203

204-
Some other languages like allow multiple inheritance. JavaScript does not support multiple inheritance, but mixins can be implemented by copying methods into prototype.
204+
Some other languages allow multiple inheritance. JavaScript does not support multiple inheritance, but mixins can be implemented by copying methods into prototype.
205205

206206
We can use mixins as a way to augment a class by multiple behaviors, like event-handling as we have seen above.
207207

Diff for: 1-js/10-error-handling/1-try-catch/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ try {
8585
}
8686
```
8787
88-
The JavaScript engine first reads the code, and then runs it. The errors that occur on the reading phrase are called "parse-time" errors and are unrecoverable (from inside that code). That's because the engine can't understand the code.
88+
The JavaScript engine first reads the code, and then runs it. The errors that occur on the reading phase are called "parse-time" errors and are unrecoverable (from inside that code). That's because the engine can't understand the code.
8989
9090
So, `try..catch` can only handle errors that occur in the valid code. Such errors are called "runtime errors" or, sometimes, "exceptions".
9191
````
@@ -522,7 +522,7 @@ alert(result || "error occurred");
522522
alert( `execution took ${diff}ms` );
523523
```
524524
525-
You can check by running the code with entering `35` into `prompt` -- it executes normally, `finally` after `try`. And then enter `-1` -- there will be an immediate error, an the execution will take `0ms`. Both measurements are done correctly.
525+
You can check by running the code with entering `35` into `prompt` -- it executes normally, `finally` after `try`. And then enter `-1` -- there will be an immediate error, and the execution will take `0ms`. Both measurements are done correctly.
526526
527527
In other words, the function may finish with `return` or `throw`, that doesn't matter. The `finally` clause executes in both cases.
528528

Diff for: 1-js/13-modules/01-modules-intro/article.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ Compare to regular script below:
266266
267267
Please note: the second script actually works before the first! So we'll see `undefined` first, and then `object`.
268268
269-
That's because modules are deferred, so way wait for the document to be processed. The regular scripts runs immediately, so we saw its output first.
269+
That's because modules are deferred, so we wait for the document to be processed. The regular scripts runs immediately, so we saw its output first.
270270
271271
When using modules, we should be aware that HTML-page shows up as it loads, and JavaScript modules run after that, so the user may see the page before the JavaScript application is ready. Some functionality may not work yet. We should put "loading indicators", or otherwise ensure that the visitor won't be confused by that.
272272

Diff for: 1-js/99-js-misc/02-eval/article.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,9 @@ Right now, there's almost no reason to use `eval`. If someone is using it, there
7777

7878
Please note that its ability to access outer variables has side-effects.
7979

80-
Code minifiers (tools used before JS gets to production, to compress it) replace local variables with shorter ones for optimization. That's usually safe, but not if `eval` is used, as it may reference them. So minifiers don't replace all local variables that might be visible from `eval`. That negatively affects code compression ratio.
80+
Code minifiers (tools used before JS gets to production, to compress it) rename local variables into shorter ones (like `a`, `b` etc) to make the code smaller. That's usually safe, but not if `eval` is used, as local variables may be accessed from eval'ed code string. So minifiers don't do that renaming for all variables potentially visible from `eval`. That negatively affects code compression ratio.
8181

82-
Using outer local variables inside `eval` is a bad programming practice, as it makes maintaining the code more difficult.
82+
Using outer local variables inside `eval` is also considered a bad programming practice, as it makes maintaining the code more difficult.
8383

8484
There are two ways how to be totally safe from such problems.
8585

0 commit comments

Comments
 (0)