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/08-operators/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
@@ -437,7 +437,7 @@ The list of operators:
437
437
- RIGHT SHIFT ( `>>` )
438
438
- ZERO-FILL RIGHT SHIFT ( `>>>` )
439
439
440
-
These operators are used very rarely, when we need to fiddle with numbers on the very lowest (bitwise) level. We won't need these operators any time soon, as web development has little use of them, but in some special areas, such as cryptography, they are useful. You can read the [Bitwise Operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#Bitwise) chapter on MDN when a need arises.
440
+
These operators are used very rarely, when we need to fiddle with numbers on the very lowest (bitwise) level. We won't need these operators any time soon, as web development has little use of them, but in some special areas, such as cryptography, they are useful. You can read the [Bitwise Operators](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Expressions_and_Operators#bitwise_operators) chapter on MDN when a need arises.
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/12-nullish-coalescing-operator/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
@@ -4,7 +4,7 @@
4
4
5
5
The nullish coalescing operator is written as two question marks `??`.
6
6
7
-
As it treats `null` and `undefined` similarly, we'll use a special term here, in this article. We'll say that an expression is "defined" when it's neither `null` nor `undefined`.
7
+
As it treats `null` and `undefined` similarly, we'll use a special term here, in this article. For brevity, we'll say that a value is "defined" when it's neither `null` nor `undefined`.
8
8
9
9
The result of `a ?? b` is:
10
10
- if `a` is defined, then `a`,
@@ -22,9 +22,9 @@ result = (a !== null && a !== undefined) ? a : b;
22
22
23
23
Now it should be absolutely clear what `??` does. Let's see where it helps.
24
24
25
-
The common use case for `??` is to provide a default value for a potentially undefined variable.
25
+
The common use case for `??` is to provide a default value.
26
26
27
-
For example, here we show `user` if defined, otherwise `Anonymous`:
27
+
For example, here we show `user` if its value isn't `null/undefined`, otherwise `Anonymous`:
We can also use a sequence of `??` to select the first value from a list that isn't `null/undefined`.
44
44
45
-
Let's say we have a user's data in variables `firstName`, `lastName` or `nickName`. All of them may be not defined, if the user decided not to enter a value.
45
+
Let's say we have a user's data in variables `firstName`, `lastName` or `nickName`. All of them may be not defined, if the user decided not to fill in the corresponding values.
46
46
47
-
We'd like to display the user name using one of these variables, or show "Anonymous" if all of them aren't defined.
47
+
We'd like to display the user name using one of these variables, or show "Anonymous" if all of them are `null/undefined`.
48
48
49
49
Let's use the `??` operator for that:
50
50
@@ -110,7 +110,7 @@ The precedence of the `??` operator is the same as `||`. They both equal `4` in
110
110
111
111
That means that, just like `||`, the nullish coalescing operator `??` is evaluated before `=` and `?`, but after most other operations, such as `+`, `*`.
112
112
113
-
So if we'd like to choose a value with `??`in an expression with other operators, consider adding parentheses:
113
+
So we may need to add parentheses in expressions like this:
114
114
115
115
```js run
116
116
let height =null;
@@ -128,7 +128,7 @@ Otherwise, if we omit parentheses, then as `*` has the higher precedence than `?
128
128
// without parentheses
129
129
let area = height ??100* width ??50;
130
130
131
-
// ...works the same as this (probably not what we want):
Copy file name to clipboardExpand all lines: 1-js/02-first-steps/16-function-expressions/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
@@ -194,7 +194,7 @@ First, the syntax: how to differentiate between them in the code.
194
194
return a + b;
195
195
}
196
196
```
197
-
-*Function Expression:* a function, created inside an expression or inside another syntax construct. Here, the function is created at the right side of the "assignment expression" `=`:
197
+
-*Function Expression:* a function, created inside an expression or inside another syntax construct. Here, the function is created on the right side of the "assignment expression" `=`:
198
198
199
199
```js
200
200
// Function Expression
@@ -291,7 +291,7 @@ if (age < 18) {
291
291
welcome(); // \ (runs)
292
292
*/!*
293
293
// |
294
-
functionwelcome() { // |
294
+
functionwelcome() { // |
295
295
alert("Hello!"); // | Function Declaration is available
296
296
} // | everywhere in the block where it's declared
Copy file name to clipboardExpand all lines: 1-js/04-object-basics/01-object/article.md
+10-9Lines changed: 10 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -44,7 +44,7 @@ The resulting `user` object can be imagined as a cabinet with two signed files l
44
44
45
45

46
46
47
-
We can add, remove and read files from it any time.
47
+
We can add, remove and read files from it at any time.
48
48
49
49
Property values are accessible using the dot notation:
50
50
@@ -62,7 +62,7 @@ user.isAdmin = true;
62
62
63
63

64
64
65
-
To remove a property, we can use `delete` operator:
65
+
To remove a property, we can use the `delete` operator:
66
66
67
67
```js
68
68
deleteuser.age;
@@ -201,13 +201,13 @@ let bag = {
201
201
};
202
202
```
203
203
204
-
Square brackets are much more powerful than the dot notation. They allow any property names and variables. But they are also more cumbersome to write.
204
+
Square brackets are much more powerful than dot notation. They allow any property names and variables. But they are also more cumbersome to write.
205
205
206
206
So most of the time, when property names are known and simple, the dot is used. And if we need something more complex, then we switch to square brackets.
207
207
208
208
## Property value shorthand
209
209
210
-
In real code we often use existing variables as values for property names.
210
+
In real code, we often use existing variables as values for property names.
211
211
212
212
For instance:
213
213
@@ -252,7 +252,7 @@ let user = {
252
252
253
253
## Property names limitations
254
254
255
-
As we already know, a variable cannot have a name equal to one of language-reserved words like "for", "let", "return" etc.
255
+
As we already know, a variable cannot have a name equal to one of the language-reserved words like "for", "let", "return" etc.
256
256
257
257
But for an object property, there's no such restriction:
258
258
@@ -325,7 +325,7 @@ alert( "blabla" in user ); // false, user.blabla doesn't exist
325
325
326
326
Please note that on the left side of `in` there must be a *property name*. That's usually a quoted string.
327
327
328
-
If we omit quotes, that means a variable, it should contain the actual name to be tested. For instance:
328
+
If we omit quotes, that means a variable should contain the actual name to be tested. For instance:
329
329
330
330
```js run
331
331
let user = { age:30 };
@@ -412,7 +412,7 @@ for (let code in codes) {
412
412
*/!*
413
413
```
414
414
415
-
The object may be used to suggest a list of options to the user. If we're making a site mainly for German audience then we probably want `49` to be the first.
415
+
The object may be used to suggest a list of options to the user. If we're making a site mainly for a German audience then we probably want `49` to be the first.
416
416
417
417
But if we run the code, we see a totally different picture:
418
418
@@ -424,9 +424,10 @@ The phone codes go in the ascending sorted order, because they are integers. So
The "integer property" term here means a string that can be converted to-and-from an integer without a change.
426
426
427
-
So, "49" is an integer property name, because when it's transformed to an integer number and back, it's still the same. But "+49" and "1.2" are not:
427
+
So, `"49"` is an integer property name, because when it's transformed to an integer number and back, it's still the same. But `"+49"` and `"1.2"` are not:
428
428
429
429
```js run
430
+
// Number(...) explicitly converts to a number
430
431
// Math.trunc is a built-in function that removes the decimal part
0 commit comments