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`: