From d961910b6ce994725debb3b8877ae7ff151d09d3 Mon Sep 17 00:00:00 2001 From: Ilya Kantor Date: Tue, 20 Oct 2020 11:27:04 +0300 Subject: [PATCH] Update article.md --- 1-js/04-object-basics/07-optional-chaining/article.md | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/1-js/04-object-basics/07-optional-chaining/article.md b/1-js/04-object-basics/07-optional-chaining/article.md index d570afe9..43ac309f 100644 --- a/1-js/04-object-basics/07-optional-chaining/article.md +++ b/1-js/04-object-basics/07-optional-chaining/article.md @@ -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