From 8eb6f97000888f2f74a3c3d968fbf6d85b2c2cc9 Mon Sep 17 00:00:00 2001 From: Ilya Kantor Date: Wed, 13 Jan 2021 23:44:22 +0300 Subject: [PATCH] minor fixes --- 1-js/04-object-basics/07-optional-chaining/article.md | 8 +++----- 1 file changed, 3 insertions(+), 5 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 26af97c2..0f1ea9a8 100644 --- a/1-js/04-object-basics/07-optional-chaining/article.md +++ b/1-js/04-object-basics/07-optional-chaining/article.md @@ -173,18 +173,16 @@ Then `?.()` checks the left part: if the admin function exists, then it runs (th The `?.[]` syntax also works, if we'd like to use brackets `[]` to access properties instead of dot `.`. Similar to previous cases, it allows to safely read a property from an object that may not exist. ```js run +let key = "firstName"; + let user1 = { firstName: "John" }; -let user2 = null; // Imagine, we couldn't authorize the user - -let key = "firstName"; +let user2 = null; alert( user1?.[key] ); // John alert( user2?.[key] ); // undefined - -alert( user1?.[key]?.something?.not?.existing); // undefined ``` Also we can use `?.` with `delete`: