You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/18-javascript-specials/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -55,7 +55,7 @@ To fully enable all features of modern JavaScript, we should start scripts with
55
55
56
56
The directive must be at the top of a script or at the beginning of a function body.
57
57
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.
59
59
60
60
Some modern features of the language (like classes that we'll study in the future) enable strict mode implicitly.
Copy file name to clipboardExpand all lines: 1-js/03-code-quality/03-comments/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -143,7 +143,7 @@ Such comments allow us to understand the purpose of the function and use it the
143
143
144
144
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.
145
145
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>.
147
147
148
148
Why is the task solved this way?
149
149
: 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.
Copy file name to clipboardExpand all lines: 1-js/03-code-quality/06-polyfills/article.md
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,7 +5,7 @@ The JavaScript language steadily evolves. New proposals to the language appear r
5
5
6
6
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.
7
7
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.
9
9
10
10
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).
11
11
@@ -40,9 +40,9 @@ Now the rewritten code is suitable for older JavaScript engines.
40
40
41
41
Usually, a developer runs the transpiler on their own computer, and then deploys the transpiled code to the server.
42
42
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.
44
44
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.
46
46
47
47
## Polyfills
48
48
@@ -69,9 +69,9 @@ if (!Math.trunc) { // if no such function
69
69
}
70
70
```
71
71
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.
73
73
74
-
Two interesting libraries of polyfills are:
74
+
Two interesting polyfill libraries are:
75
75
- [core js](https://github.com/zloirock/core-js) that supports a lot, allows to include only needed features.
76
76
- [polyfill.io](http://polyfill.io) service that provides a script with polyfills, depending on the features and user's browser.
77
77
@@ -80,9 +80,9 @@ Two interesting libraries of polyfills are:
80
80
81
81
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.
82
82
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.
84
84
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.
86
86
87
87
Good resources that show the current state of support for various features:
88
88
- <https://kangax.github.io/compat-table/es6/> - for pure JavaScript.
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/03-garbage-collection/article.md
+3-3Lines changed: 3 additions & 3 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -205,8 +205,8 @@ Modern engines implement advanced algorithms of garbage collection.
205
205
206
206
A general book "The Garbage Collection Handbook: The Art of Automatic Memory Management" (R. Jones et al) covers some of them.
207
207
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).
209
209
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.
211
211
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.
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/08-symbol/article.md
+9-9Lines changed: 9 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ By specification, only two primitive types may serve as object property keys:
8
8
9
9
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"]`.
10
10
11
-
Till now we've been using only strings.
11
+
Until now we've been using only strings.
12
12
13
13
Now let's explore symbols, see what they can do for us.
14
14
@@ -22,14 +22,14 @@ A value of this type can be created using `Symbol()`:
22
22
let id =Symbol();
23
23
```
24
24
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:
26
26
27
27
```js
28
28
// id is a symbol with the description "id"
29
29
let id =Symbol("id");
30
30
```
31
31
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.
33
33
34
34
For instance, here are two symbols with the same description -- they are not equal:
35
35
@@ -44,7 +44,7 @@ alert(id1 == id2); // false
44
44
45
45
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.
46
46
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.
48
48
49
49
````warn header="Symbols don't auto-convert to a string"
50
50
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
103
103
104
104
What's the benefit of using `Symbol("id")` over a string `"id"`?
105
105
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.
107
107
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.
109
109
110
110
Then that script can create its own `Symbol("id")`, like this:
111
111
@@ -217,12 +217,12 @@ Symbols inside the registry are called *global symbols*. If we want an applicati
217
217
```smart header="That sounds like Ruby"
218
218
In some programming languages, like Ruby, there's a single symbol per name.
219
219
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.
221
221
```
222
222
223
223
### Symbol.keyFor
224
224
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)`:
226
226
227
227
For instance:
228
228
@@ -286,4 +286,4 @@ Symbols have two main use cases:
286
286
287
287
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.
288
288
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.
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/09-object-toprimitive/article.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@
3
3
4
4
What happens when objects are added `obj1 + obj2`, subtracted `obj1 - obj2` or printed using `alert(obj)`?
5
5
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).
7
7
8
8
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.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/04-array/article.md
+13-8Lines changed: 13 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -512,21 +512,26 @@ That's simple: don't use the `==` operator. Instead, compare them item-by-item i
512
512
513
513
Array is a special kind of object, suited to storing and managing ordered data items.
514
514
515
-
-The declaration:
515
+
The declaration:
516
516
517
-
```js
518
-
// square brackets (usual)
519
-
let arr = [item1, item2...];
517
+
```js
518
+
// square brackets (usual)
519
+
let arr = [item1, item2...];
520
520
521
-
// new Array (exceptionally rare)
522
-
let arr =newArray(item1, item2...);
523
-
```
521
+
// new Array (exceptionally rare)
522
+
let arr =newArray(item1, item2...);
523
+
```
524
524
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.
526
526
527
527
- The `length` property is the array length or, to be precise, its last numeric index plus one. It is auto-adjusted by array methods.
528
528
- If we shorten `length` manually, the array is truncated.
529
529
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
+
530
535
We can use an array as a deque with the following operations:
: Create the date with the given components in the local time zone. Only the first two arguments are obligatory.
59
59
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.
61
61
- The `month` count starts with `0` (Jan), up to `11` (Dec).
62
62
- The `date` parameter is actually the day of month, if absent then `1` is assumed.
63
63
- 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:
407
407
```js run
408
408
let date = new Date( Date.parse('2012-01-26T13:51:50.417-07:00') );
Copy file name to clipboardExpand all lines: 1-js/09-classes/02-class-inheritance/article.md
+3-6Lines changed: 3 additions & 6 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -122,7 +122,7 @@ class Rabbit extends Animal {
122
122
}
123
123
```
124
124
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.
126
126
127
127
Classes provide `"super"` keyword for that.
128
128
@@ -176,6 +176,7 @@ Now `Rabbit` has the `stop` method that calls the parent `super.stop()` in the p
176
176
As was mentioned in the chapter <info:arrow-functions>, arrow functions do not have `super`.
177
177
178
178
If accessed, it's taken from the outer function. For instance:
@@ -386,13 +384,12 @@ In our case, `Rabbit` is the derived class. There's no `constructor()` in it. As
386
384
387
385
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.
388
386
389
-
This subtle difference between fields and methods is specific to JavaScript
387
+
This subtle difference between fields and methods is specific to JavaScript.
390
388
391
389
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.
392
390
393
391
If it becomes a problem, one can fix it by using methods or getters/setters instead of fields.
0 commit comments