Skip to content

Commit 4b2aa8d

Browse files
committed
merging all conflicts
2 parents ce8304b + 7533c71 commit 4b2aa8d

File tree

20 files changed

+82
-38
lines changed

20 files changed

+82
-38
lines changed

1-js/01-getting-started/2-manuals-specifications/article.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ Uma nova versão dessa especificação é lançada todos os anos. Entre estes la
1313

1414
Para ler sobre as mais novas funcionalidades (*bleeding-edge features*), incluindo as que estão em fase de padronização (chamadas também de "estágio 3"), veja as suas propostas em <https://github.com/tc39/proposals>.
1515

16+
<<<<<<< HEAD
1617
E mais, se você está desenvolvendo para browsers, há outras especificações que cobrem esta demanda na [segunda parte](info:browser-environment) do tutorial.
18+
=======
19+
Also, if you're developing for the browser, then there are other specifications covered in the [second part](info:browser-environment) of the tutorial.
20+
>>>>>>> 7533c719fbf62ba57188d6d51fe4c038b282bd0c
1721
1822
## Manuais
1923

1-js/02-first-steps/08-operators/3-primitive-conversions-questions/solution.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ true + false = 1
99
"$" + 4 + 5 = "$45"
1010
"4" - 2 = 2
1111
"4px" - 2 = NaN
12-
7 / 0 = Infinity
1312
" -9 " + 5 = " -9 5" // (3)
1413
" -9 " - 5 = -14 // (4)
1514
null + 1 = 1 // (5)

1-js/02-first-steps/08-operators/3-primitive-conversions-questions/task.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ true + false
1616
"$" + 4 + 5
1717
"4" - 2
1818
"4px" - 2
19-
7 / 0
2019
" -9 " + 5
2120
" -9 " - 5
2221
null + 1

1-js/02-first-steps/10-ifelse/2-check-standard/task.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ importance: 2
66

77
Using the `if..else` construct, write the code which asks: 'What is the "official" name of JavaScript?'
88

9-
If the visitor enters "ECMAScript", then output "Right!", otherwise -- output: "Didn't know? ECMAScript!"
9+
If the visitor enters "ECMAScript", then output "Right!", otherwise -- output: "You don't know? ECMAScript!"
1010

1111
![](ifelse_task2.svg)
1212

1-js/02-first-steps/11-logical-operators/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Logical operators
22

3-
There are three logical operators in JavaScript: `||` (OR), `&&` (AND), `!` (NOT).
3+
There are four logical operators in JavaScript: `||` (OR), `&&` (AND), `!` (NOT), `??` (Nullish Coalescing). Here we cover the first three, the `??` operator is in the next article.
44

55
Although they are called "logical", they can be applied to values of any type, not only boolean. Their result can also be of any type.
66

1-js/02-first-steps/12-nullish-coalescing-operator/article.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22

33
[recent browser="new"]
44

5-
Here, in this article, we'll say that an expression is "defined" when it's neither `null` nor `undefined`.
6-
75
The nullish coalescing operator is written as two question marks `??`.
86

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`.
8+
99
The result of `a ?? b` is:
1010
- if `a` is defined, then `a`,
1111
- if `a` isn't defined, then `b`.
1212

13-
1413
In other words, `??` returns the first argument if it's not `null/undefined`. Otherwise, the second one.
1514

1615
The nullish coalescing operator isn't anything completely new. It's just a nice syntax to get the first "defined" value of the two.
@@ -21,29 +20,31 @@ We can rewrite `result = a ?? b` using the operators that we already know, like
2120
result = (a !== null && a !== undefined) ? a : b;
2221
```
2322

23+
Now it should be absolutely clear what `??` does. Let's see where it helps.
24+
2425
The common use case for `??` is to provide a default value for a potentially undefined variable.
2526

26-
For example, here we show `Anonymous` if `user` isn't defined:
27+
For example, here we show `user` if defined, otherwise `Anonymous`:
2728

2829
```js run
2930
let user;
3031

31-
alert(user ?? "Anonymous"); // Anonymous
32+
alert(user ?? "Anonymous"); // Anonymous (user not defined)
3233
```
3334
34-
Of course, if `user` had any value except `null/undefined`, then we would see it instead:
35+
Here's the example with `user` assigned to a name:
3536
3637
```js run
3738
let user = "John";
3839

39-
alert(user ?? "Anonymous"); // John
40+
alert(user ?? "Anonymous"); // John (user defined)
4041
```
4142
4243
We can also use a sequence of `??` to select the first value from a list that isn't `null/undefined`.
4344
44-
Let's say we have a user's data in variables `firstName`, `lastName` or `nickName`. All of them may be undefined, 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 enter a value.
4546
46-
We'd like to display the user name using one of these variables, or show "Anonymous" if all of them are undefined.
47+
We'd like to display the user name using one of these variables, or show "Anonymous" if all of them aren't defined.
4748
4849
Let's use the `??` operator for that:
4950
@@ -75,7 +76,7 @@ alert(firstName || lastName || nickName || "Anonymous"); // Supercoder
7576
*/!*
7677
```
7778
78-
The OR `||` operator exists since the beginning of JavaScript, so developers were using it for such purposes for a long time.
79+
Historically, the OR `||` operator was there first. It exists since the beginning of JavaScript, so developers were using it for such purposes for a long time.
7980
8081
On the other hand, the nullish coalescing operator `??` was added to JavaScript only recently, and the reason for that was that people weren't quite happy with `||`.
8182
@@ -96,16 +97,18 @@ alert(height || 100); // 100
9697
alert(height ?? 100); // 0
9798
```
9899
99-
- The `height || 100` checks `height` for being a falsy value, and it really is.
100-
- so the result is the second argument, `100`.
100+
- The `height || 100` checks `height` for being a falsy value, and it's `0`, falsy indeed.
101+
- so the result of `||` is the second argument, `100`.
101102
- The `height ?? 100` checks `height` for being `null/undefined`, and it's not,
102103
- so the result is `height` "as is", that is `0`.
103104
104-
If the zero height is a valid value, that shouldn't be replaced with the default, then `??` does just the right thing.
105+
In practice, the zero height is often a valid value, that shouldn't be replaced with the default. So `??` does just the right thing.
105106
106107
## Precedence
107108
108-
The precedence of the `??` operator is rather low: `5` in the [MDN table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table). So `??` is evaluated before `=` and `?`, but after most other operations, such as `+`, `*`.
109+
The precedence of the `??` operator is about the same as `||`, just a bit lower. It equals `5` in the [MDN table](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Operator_Precedence#Table), while `||` is `6`.
110+
111+
That means that, just like `||`, the nullish coalescing operator `??` is evaluated before `=` and `?`, but after most other operations, such as `+`, `*`.
109112
110113
So if we'd like to choose a value with `??` in an expression with other operators, consider adding parentheses:
111114
@@ -139,7 +142,7 @@ The code below triggers a syntax error:
139142
let x = 1 && 2 ?? 3; // Syntax error
140143
```
141144
142-
The limitation is surely debatable, but it was added to the language specification with the purpose to avoid programming mistakes, when people start to switch to `??` from `||`.
145+
The limitation is surely debatable, it was added to the language specification with the purpose to avoid programming mistakes, when people start to switch from `||` to `??`.
143146
144147
Use explicit parentheses to work around it:
145148

1-js/02-first-steps/17-arrow-functions-basics/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ Existe outra sintaxe, muito simples e concisa, para criar funções, e que geral
55
É chamada de "funções seta" (*"arrow functions"*), porque tem este aspeto:
66

77
```js
8-
let func = (arg1, arg2, ...argN) => expression
8+
let func = (arg1, arg2, ..., argN) => expression
99
```
1010

1111
...Isto, cria a função `func` com os argumentos `arg1..argN`, depois avalia a `expression` no lado direito usando os mesmos, e retorna o seu resultado.
1212

1313
Por outras palavras, é a versão mais curta de:
1414

1515
```js
16-
let func = function(arg1, arg2, ...argN) {
16+
let func = function(arg1, arg2, ..., argN) {
1717
return expression;
1818
};
1919
```

1-js/04-object-basics/02-object-copy/article.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,8 @@ let clone = Object.assign({}, user);
186186
187187
It copies all properties of `user` into the empty object and returns it.
188188
189+
There are also other methods of cloning an object, e.g. using the [spread operator](info:rest-parameters-spread) `clone = {...user}`, covered later in the tutorial.
190+
189191
## Nested cloning
190192
191193
Until now we assumed that all properties of `user` are primitive. But properties can be references to other objects. What to do with them?

1-js/04-object-basics/04-object-methods/8-chain-calls/solution.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ let ladder = {
2121
return this;
2222
*/!*
2323
}
24-
}
24+
};
2525

2626
ladder.up().up().down().up().down().showStep(); // 1
2727
```

1-js/04-object-basics/07-optional-chaining/article.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,9 @@ userGuest.admin?.(); // nothing (no such method)
166166
*/!*
167167
```
168168
169-
Here, in both lines we first use the dot (`user1.admin`) to get `admin` property, because the user object must exist, so it's safe read from it.
169+
Here, in both lines we first use the dot (`userAdmin.admin`) to get `admin` property, because we assume that the user object exists, so it's safe read from it.
170170
171-
Then `?.()` checks the left part: if the admin function exists, then it runs (that's so for `user1`). Otherwise (for `user2`) the evaluation stops without errors.
171+
Then `?.()` checks the left part: if the admin function exists, then it runs (that's so for `userAdmin`). Otherwise (for `userGuest`) the evaluation stops without errors.
172172
173173
The `?.[]` syntax also works, if we'd like to use brackets `[]` to access properties instead of dot `.`. Similar to previous cases, it allows to safely read a property from an object that may not exist.
174174

0 commit comments

Comments
 (0)