From 9d4a69d42d96c49f9c3ac5046ad765a02dd50676 Mon Sep 17 00:00:00 2001 From: Ilya Kantor Date: Tue, 20 Oct 2020 08:26:40 +0300 Subject: [PATCH] Update article.md --- 1-js/04-object-basics/07-optional-chaining/article.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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 4deebd25..fc189345 100644 --- a/1-js/04-object-basics/07-optional-chaining/article.md +++ b/1-js/04-object-basics/07-optional-chaining/article.md @@ -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, consider objects that hold user data. +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`, the attempt to get `user.address.street` fails with an error. Although, in many practical cases we'd prefer to get `undefined` instead of an error here (meaning "no street"). +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 said, in many practical cases we'd prefer to get `undefined` instead of an error here (meaning "no street"). ...And another example. In the web development, we may need the information about an element on the page. The element is returned by `document.querySelector('.elem')`, and the catch is again - that it sometimes doesn't exist: