Skip to content

Commit 79d2845

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-2901e0c6
2 parents a4101ca + 2901e0c commit 79d2845

10 files changed

Lines changed: 40 additions & 39 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ To fully enable all features of modern JavaScript, we should start scripts with
5555

5656
The directive must be at the top of a script or at the beginning of a function body.
5757

58-
Without `"use strict"`, everything still works, but some features behave in the old-fashion, "compatible" way. We'd generally prefer the modern behavior.
58+
Without `"use strict"`, everything still works, but some features behave in the old-fashioned, "compatible" way. We'd generally prefer the modern behavior.
5959

6060
Some modern features of the language (like classes that we'll study in the future) enable strict mode implicitly.
6161

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Such comments allow us to understand the purpose of the function and use it the
143143

144144
By the way, many editors like [WebStorm](https://www.jetbrains.com/webstorm/) can understand them as well and use them to provide autocomplete and some automatic code-checking.
145145

146-
Also, there are tools like [JSDoc 3](https://github.com/jsdoc3/jsdoc) that can generate HTML-documentation from the comments. You can read more information about JSDoc at <http://usejsdoc.org/>.
146+
Also, there are tools like [JSDoc 3](https://github.com/jsdoc3/jsdoc) that can generate HTML-documentation from the comments. You can read more information about JSDoc at <https://jsdoc.app>.
147147

148148
Why is the task solved this way?
149149
: What's written is important. But what's *not* written may be even more important to understand what's going on. Why is the task solved exactly this way? The code gives no answer.

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The JavaScript language steadily evolves. New proposals to the language appear r
55

66
Teams behind JavaScript engines have their own ideas about what to implement first. They may decide to implement proposals that are in draft and postpone things that are already in the spec, because they are less interesting or just harder to do.
77

8-
So it's quite common for an engine to implement only the part of the standard.
8+
So it's quite common for an engine to implement only part of the standard.
99

1010
A good page to see the current state of support for language features is <https://kangax.github.io/compat-table/es6/> (it's big, we have a lot to study yet).
1111

@@ -40,9 +40,9 @@ Now the rewritten code is suitable for older JavaScript engines.
4040
4141
Usually, a developer runs the transpiler on their own computer, and then deploys the transpiled code to the server.
4242
43-
Speaking of names, [Babel](https://babeljs.io) is one of the most prominent transpilers out there.
43+
Speaking of names, [Babel](https://babeljs.io) is one of the most prominent transpilers out there.
4444
45-
Modern project build systems, such as [webpack](https://webpack.js.org/), provide means to run transpiler automatically on every code change, so it's very easy to integrate into development process.
45+
Modern project build systems, such as [webpack](https://webpack.js.org/), provide a means to run a transpiler automatically on every code change, so it's very easy to integrate into the development process.
4646
4747
## Polyfills
4848
@@ -69,9 +69,9 @@ if (!Math.trunc) { // if no such function
6969
}
7070
```
7171
72-
JavaScript is a highly dynamic language, scripts may add/modify any functions, even including built-in ones.
72+
JavaScript is a highly dynamic language. Scripts may add/modify any function, even built-in ones.
7373
74-
Two interesting libraries of polyfills are:
74+
Two interesting polyfill libraries are:
7575
- [core js](https://github.com/zloirock/core-js) that supports a lot, allows to include only needed features.
7676
- [polyfill.io](http://polyfill.io) service that provides a script with polyfills, depending on the features and user's browser.
7777
@@ -80,9 +80,9 @@ Two interesting libraries of polyfills are:
8080
8181
In this chapter we'd like to motivate you to study modern and even "bleeding-edge" language features, even if they aren't yet well-supported by JavaScript engines.
8282
83-
Just don't forget to use transpiler (if using modern syntax or operators) and polyfills (to add functions that may be missing). And they'll ensure that the code works.
83+
Just don't forget to use a transpiler (if using modern syntax or operators) and polyfills (to add functions that may be missing). They'll ensure that the code works.
8484
85-
For example, later when you're familiar with JavaScript, you can setup a code build system based on [webpack](https://webpack.js.org/) with [babel-loader](https://github.com/babel/babel-loader) plugin.
85+
For example, later when you're familiar with JavaScript, you can setup a code build system based on [webpack](https://webpack.js.org/) with the [babel-loader](https://github.com/babel/babel-loader) plugin.
8686
8787
Good resources that show the current state of support for various features:
8888
- <https://kangax.github.io/compat-table/es6/> - for pure JavaScript.

1-js/04-object-basics/03-garbage-collection/article.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -205,8 +205,8 @@ Modern engines implement advanced algorithms of garbage collection.
205205

206206
A general book "The Garbage Collection Handbook: The Art of Automatic Memory Management" (R. Jones et al) covers some of them.
207207

208-
If you are familiar with low-level programming, the more detailed information about V8 garbage collector is in the article [A tour of V8: Garbage Collection](http://jayconrod.com/posts/55/a-tour-of-v8-garbage-collection).
208+
If you are familiar with low-level programming, more detailed information about V8's garbage collector is in the article [A tour of V8: Garbage Collection](http://jayconrod.com/posts/55/a-tour-of-v8-garbage-collection).
209209

210-
[V8 blog](https://v8.dev/) also publishes articles about changes in memory management from time to time. Naturally, to learn the garbage collection, you'd better prepare by learning about V8 internals in general and read the blog of [Vyacheslav Egorov](http://mrale.ph) who worked as one of V8 engineers. I'm saying: "V8", because it is best covered with articles in the internet. For other engines, many approaches are similar, but garbage collection differs in many aspects.
210+
The [V8 blog](https://v8.dev/) also publishes articles about changes in memory management from time to time. Naturally, to learn more about garbage collection, you'd better prepare by learning about V8 internals in general and read the blog of [Vyacheslav Egorov](http://mrale.ph) who worked as one of the V8 engineers. I'm saying: "V8", because it is best covered by articles on the internet. For other engines, many approaches are similar, but garbage collection differs in many aspects.
211211

212-
In-depth knowledge of engines is good when you need low-level optimizations. It would be wise to plan that as the next step after you're familiar with the language.
212+
In-depth knowledge of engines is good when you need low-level optimizations. It would be wise to plan that as the next step after you're familiar with the language.

1-js/04-object-basics/08-symbol/article.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ By specification, only two primitive types may serve as object property keys:
88

99
Otherwise, if one uses another type, such as number, it's autoconverted to string. So that `obj[1]` is the same as `obj["1"]`, and `obj[true]` is the same as `obj["true"]`.
1010

11-
Till now we've been using only strings.
11+
Until now we've been using only strings.
1212

1313
Now let's explore symbols, see what they can do for us.
1414

@@ -22,14 +22,14 @@ A value of this type can be created using `Symbol()`:
2222
let id = Symbol();
2323
```
2424

25-
Upon creation, we can give symbol a description (also called a symbol name), mostly useful for debugging purposes:
25+
Upon creation, we can give symbols a description (also called a symbol name), mostly useful for debugging purposes:
2626

2727
```js
2828
// id is a symbol with the description "id"
2929
let id = Symbol("id");
3030
```
3131

32-
Symbols are guaranteed to be unique. Even if we create many symbols with the same description, they are different values. The description is just a label that doesn't affect anything.
32+
Symbols are guaranteed to be unique. Even if we create many symbols with exactly the same description, they are different values. The description is just a label that doesn't affect anything.
3333

3434
For instance, here are two symbols with the same description -- they are not equal:
3535

@@ -44,7 +44,7 @@ alert(id1 == id2); // false
4444

4545
If you are familiar with Ruby or another language that also has some sort of "symbols" -- please don't be misguided. JavaScript symbols are different.
4646

47-
So, to summarize, symbols are "primitive unique values" with optional description. Let's see where we can use them.
47+
So, to summarize, a symbol is a "primitive unique value" with an optional description. Let's see where we can use them.
4848

4949
````warn header="Symbols don't auto-convert to a string"
5050
Most values in JavaScript support implicit conversion to a string. For instance, we can `alert` almost any value, and it will work. Symbols are special. They don't auto-convert.
@@ -103,9 +103,9 @@ alert( user[id] ); // we can access the data using the symbol as the key
103103

104104
What's the benefit of using `Symbol("id")` over a string `"id"`?
105105

106-
As `user` objects belongs to another code, and that code also works with them, we shouldn't just add any fields to it. That's unsafe. But a symbol cannot be accessed accidentally, the third-party code probably won't even see it, so it's probably all right to do.
106+
As `user` objects belong to another codebase, it's unsafe to add fields to them, since we might affect pre-defined behavior in that other codebase. However, symbols cannot be accessed accidentally. The third-party code won't be aware of newly defined symbols, so it's safe to add symbols to the `user` objects.
107107

108-
Also, imagine that another script wants to have its own identifier inside `user`, for its own purposes. That may be another JavaScript library, so that the scripts are completely unaware of each other.
108+
Also, imagine that another script wants to have its own identifier inside `user`, for its own purposes.
109109

110110
Then that script can create its own `Symbol("id")`, like this:
111111

@@ -217,12 +217,12 @@ Symbols inside the registry are called *global symbols*. If we want an applicati
217217
```smart header="That sounds like Ruby"
218218
In some programming languages, like Ruby, there's a single symbol per name.
219219
220-
In JavaScript, as we can see, that's right for global symbols.
220+
In JavaScript, as we can see, that's true for global symbols.
221221
```
222222

223223
### Symbol.keyFor
224224

225-
For global symbols, not only `Symbol.for(key)` returns a symbol by name, but there's a reverse call: `Symbol.keyFor(sym)`, that does the reverse: returns a name by a global symbol.
225+
We have seen that for global symbols, `Symbol.for(key)` returns a symbol by name. To do the opposite -- return a name by global symbol -- we can use: `Symbol.keyFor(sym)`:
226226

227227
For instance:
228228

@@ -286,4 +286,4 @@ Symbols have two main use cases:
286286

287287
2. There are many system symbols used by JavaScript which are accessible as `Symbol.*`. We can use them to alter some built-in behaviors. For instance, later in the tutorial we'll use `Symbol.iterator` for [iterables](info:iterable), `Symbol.toPrimitive` to setup [object-to-primitive conversion](info:object-toprimitive) and so on.
288288

289-
Technically, symbols are not 100% hidden. There is a built-in method [Object.getOwnPropertySymbols(obj)](mdn:js/Object/getOwnPropertySymbols) that allows us to get all symbols. Also there is a method named [Reflect.ownKeys(obj)](mdn:js/Reflect/ownKeys) that returns *all* keys of an object including symbolic ones. So they are not really hidden. But most libraries, built-in functions and syntax constructs don't use these methods.
289+
Technically, symbols are not 100% hidden. There is a built-in method [Object.getOwnPropertySymbols(obj)](mdn:js/Object/getOwnPropertySymbols) that allows us to get all symbols. Also there is a method named [Reflect.ownKeys(obj)](mdn:js/Reflect/ownKeys) that returns *all* keys of an object including symbolic ones. But most libraries, built-in functions and syntax constructs don't use these methods.

1-js/04-object-basics/09-object-toprimitive/article.md

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

44
What happens when objects are added `obj1 + obj2`, subtracted `obj1 - obj2` or printed using `alert(obj)`?
55

6-
JavaScript doesn't exactly allow to customize how operators work on objects. Unlike some other programming languages, such as Ruby or C++, we can't implement a special object method to handle an addition (or other operators).
6+
JavaScript doesn't allow you to customize how operators work on objects. Unlike some other programming languages, such as Ruby or C++, we can't implement a special object method to handle addition (or other operators).
77

88
In case of such operations, objects are auto-converted to primitives, and then the operation is carried out over these primitives and results in a primitive value.
99

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -512,21 +512,26 @@ That's simple: don't use the `==` operator. Instead, compare them item-by-item i
512512

513513
Array is a special kind of object, suited to storing and managing ordered data items.
514514

515-
- The declaration:
515+
The declaration:
516516

517-
```js
518-
// square brackets (usual)
519-
let arr = [item1, item2...];
517+
```js
518+
// square brackets (usual)
519+
let arr = [item1, item2...];
520520

521-
// new Array (exceptionally rare)
522-
let arr = new Array(item1, item2...);
523-
```
521+
// new Array (exceptionally rare)
522+
let arr = new Array(item1, item2...);
523+
```
524524

525-
The call to `new Array(number)` creates an array with the given length, but without elements.
525+
The call to `new Array(number)` creates an array with the given length, but without elements.
526526

527527
- The `length` property is the array length or, to be precise, its last numeric index plus one. It is auto-adjusted by array methods.
528528
- If we shorten `length` manually, the array is truncated.
529529

530+
Getting the elements:
531+
532+
- we can get element by its index, like `arr[0]`
533+
- also we can use `at(i)` method to get negative-index elements, for negative values of `i`, it steps back from the end of the array. In the rest it works same as `arr[i]`, if `i >= 0`.
534+
530535
We can use an array as a deque with the following operations:
531536

532537
- `push(...items)` adds `items` to the end.

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ To create a new `Date` object call `new Date()` with one of the following argume
5757
`new Date(year, month, date, hours, minutes, seconds, ms)`
5858
: Create the date with the given components in the local time zone. Only the first two arguments are obligatory.
5959

60-
- The `year` must have 4 digits: `2013` is okay, `98` is not.
60+
- The `year` should have 4 digits. For compatibility, 2 digits are also accepted and considered `19xx`, e.g. `98` is same as `1998` here, but always using 4 digits is strongly encouraged.
6161
- The `month` count starts with `0` (Jan), up to `11` (Dec).
6262
- The `date` parameter is actually the day of month, if absent then `1` is assumed.
6363
- If `hours/minutes/seconds/ms` is absent, they are assumed to be equal `0`.
@@ -407,7 +407,7 @@ We can instantly create a `new Date` object from the timestamp:
407407
```js run
408408
let date = new Date( Date.parse('2012-01-26T13:51:50.417-07:00') );
409409

410-
alert(date);
410+
alert(date);
411411
```
412412

413413
## Summary

1-js/08-prototypes/01-prototype-inheritance/article.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,6 @@ There are only two limitations:
131131

132132
Also it may be obvious, but still: there can be only one `[[Prototype]]`. An object may not inherit from two others.
133133

134-
135134
```smart header="`__proto__` is a historical getter/setter for `[[Prototype]]`"
136135
It's a common mistake of novice developers not to know the difference between these two.
137136

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ class Rabbit extends Animal {
122122
}
123123
```
124124
125-
Usually we don't want to totally replace a parent method, but rather to build on top of it to tweak or extend its functionality. We do something in our method, but call the parent method before/after it or in the process.
125+
Usually, however, we don't want to totally replace a parent method, but rather to build on top of it to tweak or extend its functionality. We do something in our method, but call the parent method before/after it or in the process.
126126
127127
Classes provide `"super"` keyword for that.
128128
@@ -176,6 +176,7 @@ Now `Rabbit` has the `stop` method that calls the parent `super.stop()` in the p
176176
As was mentioned in the chapter <info:arrow-functions>, arrow functions do not have `super`.
177177
178178
If accessed, it's taken from the outer function. For instance:
179+
179180
```js
180181
class Rabbit extends Animal {
181182
stop() {
@@ -192,7 +193,6 @@ setTimeout(function() { super.stop() }, 1000);
192193
```
193194
````
194195

195-
196196
## Overriding constructor
197197

198198
With constructors it gets a little bit tricky.
@@ -296,8 +296,6 @@ alert(rabbit.earLength); // 10
296296
*/!*
297297
```
298298

299-
300-
301299
### Overriding class fields: a tricky note
302300

303301
```warn header="Advanced note"
@@ -386,13 +384,12 @@ In our case, `Rabbit` is the derived class. There's no `constructor()` in it. As
386384

387385
So, `new Rabbit()` calls `super()`, thus executing the parent constructor, and (per the rule for derived classes) only after that its class fields are initialized. At the time of the parent constructor execution, there are no `Rabbit` class fields yet, that's why `Animal` fields are used.
388386

389-
This subtle difference between fields and methods is specific to JavaScript
387+
This subtle difference between fields and methods is specific to JavaScript.
390388

391389
Luckily, this behavior only reveals itself if an overridden field is used in the parent constructor. Then it may be difficult to understand what's going on, so we're explaining it here.
392390

393391
If it becomes a problem, one can fix it by using methods or getters/setters instead of fields.
394392

395-
396393
## Super: internals, [[HomeObject]]
397394

398395
```warn header="Advanced information"

0 commit comments

Comments
 (0)