minor fixes

This commit is contained in:
Ilya Kantor 2021-01-13 23:44:22 +03:00
parent 99b2a0928f
commit 8eb6f97000

View file

@ -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. 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 ```js run
let key = "firstName";
let user1 = { let user1 = {
firstName: "John" firstName: "John"
}; };
let user2 = null; // Imagine, we couldn't authorize the user let user2 = null;
let key = "firstName";
alert( user1?.[key] ); // John alert( user1?.[key] ); // John
alert( user2?.[key] ); // undefined alert( user2?.[key] ); // undefined
alert( user1?.[key]?.something?.not?.existing); // undefined
``` ```
Also we can use `?.` with `delete`: Also we can use `?.` with `delete`: