Update article.md
This commit is contained in:
parent
fca113b532
commit
d961910b6c
1 changed files with 5 additions and 1 deletions
|
@ -74,10 +74,14 @@ That's why the optional chaining `?.` was added to the language. To solve this p
|
|||
|
||||
## Optional chaining
|
||||
|
||||
The optional chaining `?.` stops the evaluation and returns `undefined` if the part before `?.` is `undefined` or `null`.
|
||||
The optional chaining `?.` stops the evaluation if the part before `?.` is `undefined` or `null` and returns that part.
|
||||
|
||||
**Further in this article, for brevity, we'll be saying that something "exists" if it's not `null` and not `undefined`.**
|
||||
|
||||
In other words, `value?.prop`:
|
||||
- returns `value.prop` if `value` exists (just like `value.prop`),
|
||||
- otherwise (when `value` is `undefined/null`) it returns that `value`.
|
||||
|
||||
Here's the safe way to access `user.address.street` using `?.`:
|
||||
|
||||
```js run
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue