Update article.md
This commit is contained in:
parent
9ad8f66e58
commit
e92bbb1303
1 changed files with 1 additions and 3 deletions
|
@ -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.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue