Skip to content

Commit 0a9b649

Browse files
committed
Merge branch 'master' of github.com:javascript-tutorial/en.javascript.info into sync-c3a11c85
2 parents bc42248 + c3a11c8 commit 0a9b649

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

1-js/02-first-steps/09-comparison/article.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ In JavaScript they are written like this:
66

77
- Greater/less than: <code>a &gt; b</code>, <code>a &lt; b</code>.
88
- Greater/less than or equals: <code>a &gt;= b</code>, <code>a &lt;= b</code>.
9-
- Equals: `a == b`, please note the double equality sign `=` means the equality test, while a single one `a = b` means an assignment.
9+
- Equals: `a == b`, please note the double equality sign `==` means the equality test, while a single one `a = b` means an assignment.
1010
- Not equals. In maths the notation is <code>&ne;</code>, but in JavaScript it's written as <code>a != b</code>.
1111

1212
In this article we'll learn more about different types of comparisons, how JavaScript makes them, including important peculiarities.

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ AND'ing the whole path to the property ensures that all components exist, but is
4040

4141
The optional chaining `?.` stops the evaluation and returns `undefined` if the part before `?.` is `undefined` or `null`.
4242

43-
Further in this article, for brevity, we'll be saying that something "exists" if it's not `null` and not `undefined`.
44-
43+
**Further in this article, for brevity, we'll be saying that something "exists" if it's not `null` and not `undefined`.**
4544

4645
Here's the safe way to access `user.address.street`:
4746

@@ -57,14 +56,14 @@ Reading the address with `user?.address` works even if `user` object doesn't exi
5756
let user = null;
5857

5958
alert( user?.address ); // undefined
60-
6159
alert( user?.address.street ); // undefined
62-
alert( user?.address.street.anything ); // undefined
6360
```
6461
65-
Please note: the `?.` syntax works exactly where it's placed, not any further.
62+
Please note: the `?.` syntax makes optional the value before it, but not any further.
63+
64+
In the example above, `user?.` allows only `user` to be `null/undefined`.
6665
67-
In the last two lines the evaluation stops immediately after `user?.`, never accessing further properties. But if the `user` actually exists, then the further intermediate properties, such as `user.address` must exist.
66+
On the other hand, if `user` does exist, then it must have `user.address` property, otherwise `user?.address.street` gives an error at the second dot.
6867
6968
```warn header="Don't overuse the optional chaining"
7069
We should use `?.` only where it's ok that something doesn't exist.
@@ -74,14 +73,14 @@ For example, if according to our coding logic `user` object must be there, but `
7473
So, if `user` happens to be undefined due to a mistake, we'll know about it and fix it. Otherwise, coding errors can be silenced where not appropriate, and become more difficult to debug.
7574
```
7675
77-
````warn header="The variable before `?.` must exist"
78-
If there's no variable `user`, then `user?.anything` triggers an error:
76+
````warn header="The variable before `?.` must be declared"
77+
If there's no variable `user` at all, then `user?.anything` triggers an error:
7978

8079
```js run
8180
// ReferenceError: user is not defined
8281
user?.address;
8382
```
84-
The optional chaining only tests for `null/undefined`, doesn't interfere with any other language mechanics.
83+
There must be `let/const/var user`. The optional chaining works only for declared variables.
8584
````
8685

8786
## Short-circuiting

0 commit comments

Comments
 (0)