Merge pull request #2283 from leviding/patch-31

FIX: some typo error
This commit is contained in:
Ilya Kantor 2020-11-25 08:48:09 +03:00 committed by GitHub
commit 9700f82b12
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 21 additions and 21 deletions

View file

@ -9,7 +9,7 @@ The optional chaining `?.` is a safe way to access nested object properties, eve
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.
As an example, let's say we have `user` objects that hold the information about our users.
As an example, let's say we have `user` objects that hold the information about our users.
Most of our users have addresses in `user.address` property, with the street `user.address.street`, but some did not provide them.
@ -21,7 +21,7 @@ let user = {}; // a user without "address" property
alert(user.address.street); // Error!
```
That's the expected result. JavaScript works like this. As `user.address` is `undefined`, an attempt to get `user.address.street` fails with an error.
That's the expected result. JavaScript works like this. As `user.address` is `undefined`, an attempt to get `user.address.street` fails with an error.
In many practical cases we'd prefer to get `undefined` instead of an error here (meaning "no street").
@ -56,7 +56,7 @@ let user = {}; // user has no address
alert(user.address ? user.address.street ? user.address.street.name : null : null);
```
That's just awful, one may even have problems understanding such code.
That's just awful, one may even have problems understanding such code.
Don't even care to, as there's a better way to write it, using the `&&` operator: