Skip to content

Commit f4cf580

Browse files
committed
minor fixes
1 parent 545f514 commit f4cf580

File tree

1 file changed

+5
-3
lines changed
  • 1-js/04-object-basics/07-optional-chaining

1 file changed

+5
-3
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,19 @@ The optional chaining `?.` is a safe way to access nested object properties, eve
99

1010
If you've just started to read the tutorial and learn JavaScript, maybe the problem hasn't touched you yet, but it's quite common.
1111

12-
As an example, let's consider objects for user data. Most of our users enter addresses, but some did not provide them.
12+
As an example, let's consider objects for user data. Most of our users have addresses in `user.address` property, with the street `user.address.street`, but some did not provide them.
1313

1414
In such case, when we attempt to get `user.address.street`, we'll get an error:
1515

1616
```js run
17-
let user = {}; // the user happens to be without address
17+
let user = {}; // the user without "address" property
1818

1919
alert(user.address.street); // Error!
2020
```
2121

22-
Another example. In the web development, we may need to get an information about an element on the page, that sometimes doesn't exist:
22+
That's the expected result, JavaScript works like this, but many practical cases we'd prefer to get `undefined` instead of an error (meaning "no street").
23+
24+
...And another example. In the web development, we may need to get an information about an element on the page, that sometimes doesn't exist:
2325

2426
```js run
2527
// Error if the result of querySelector(...) is null

0 commit comments

Comments
 (0)