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/01-getting-started/2-manuals-specifications/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
@@ -9,7 +9,7 @@ This book is a *tutorial*. It aims to help you gradually learn the language. But
9
9
10
10
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.
11
11
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/>.
13
13
14
14
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>.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/06-type-conversions/article.md
+6-7Lines changed: 6 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -10,7 +10,7 @@ There are also cases when we need to explicitly convert a value to the expected
10
10
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>.
11
11
```
12
12
13
-
## To String
13
+
## String Conversion
14
14
15
15
String conversion happens when we need the string form of a value.
16
16
@@ -30,7 +30,7 @@ alert(typeof value); // string
30
30
31
31
String conversion is mostly obvious. A `false` becomes `"false"`, `null` becomes `"null"`, etc.
32
32
33
-
## To Number
33
+
## Numeric Conversion
34
34
35
35
Numeric conversion happens in mathematical functions and expressions automatically.
36
36
@@ -94,7 +94,7 @@ alert( '1' + 2 ); // '12' (string to the left)
94
94
This only happens when at least one of the arguments is a string. Otherwise, values are converted to numbers.
95
95
````
96
96
97
-
## To Boolean
97
+
## Boolean Conversion
98
98
99
99
Boolean conversion is the simplest one.
100
100
@@ -124,14 +124,13 @@ alert( Boolean(" ") ); // spaces, also true (any non-empty string is true)
124
124
```
125
125
````
126
126
127
-
128
127
## Summary
129
128
130
129
The three most widely used type conversions are to string, to number, and to boolean.
131
130
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.
133
132
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)`.
135
134
136
135
The conversion follows the rules:
137
136
@@ -142,7 +141,7 @@ The conversion follows the rules:
142
141
|<code>true / false</code> | `1 / 0` |
143
142
| `string` | The string is read "as is", whitespaces from both sides are ignored. An empty string becomes `0`. An error gives `NaN`. |
144
143
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)`.
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/04-object-methods/article.md
+5-5Lines changed: 5 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -98,7 +98,7 @@ It's common that an object method needs to access the information stored in the
98
98
99
99
For instance, the code inside `user.sayHi()` may need the name of the `user`.
100
100
101
-
**To access the object, a method can use the `this` keyword.**
101
+
**To access the object, a method can use `this` keyword.**
102
102
103
103
The value of `this` is the object "before dot", the one used to call the method.
104
104
@@ -167,9 +167,9 @@ If we used `this.name` instead of `user.name` inside the `alert`, then the code
167
167
168
168
## "this" is not bound
169
169
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.
171
171
172
-
There's no syntax error in the code like that:
172
+
There's no syntax error in the following example:
173
173
174
174
```js
175
175
functionsayHi() {
@@ -220,13 +220,13 @@ In this case `this` is `undefined` in strict mode. If we try to access `this.nam
220
220
221
221
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.
222
222
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.
224
224
````
225
225
226
226
```smart header="The consequences of unbound `this`"
227
227
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.
228
228
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 whatobject is "before the dot".
230
230
231
231
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.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/01-primitives-methods/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
@@ -50,7 +50,7 @@ The solution looks a little bit awkward, but here it is:
50
50
51
51
The "object wrappers" are different for each primitive type and are called: `String`, `Number`, `Boolean` and `Symbol`. Thus, they provide different sets of methods.
52
52
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`.
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.
52
52
53
-
Backticks also allow us to specify a "template function" before the first backtick. The syntax is: <code>func`string`</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`string`</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.
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.
Copy file name to clipboardExpand all lines: 1-js/05-data-types/08-weakmap-weakset/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
@@ -147,7 +147,7 @@ countUser(john);
147
147
john =null;
148
148
```
149
149
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`.
151
151
152
152
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.
0 commit comments