Update article.md

This commit is contained in:
Ilya Kantor 2020-10-20 11:29:31 +03:00 committed by GitHub
parent 9ad8f66e58
commit e92bbb1303
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -103,9 +103,7 @@ alert( user?.address.street ); // undefined
Please note: the `?.` syntax makes optional the value before it, but not any further. Please note: the `?.` syntax makes optional the value before it, but not any further.
In the example above, `user?.address.street` allows only `user` to be `null/undefined`. In the example above, `user?.address.street` allows `user` to be `null/undefined`, but `user` does exist, then further access uses a plain dot `.`, so it must have `user.address` property, otherwise `user?.address.street` gives an error at the second dot.
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.
```warn header="Don't overuse the optional chaining" ```warn header="Don't overuse the optional chaining"
We should use `?.` only where it's ok that something doesn't exist. We should use `?.` only where it's ok that something doesn't exist.