minor fixes
This commit is contained in:
parent
99b2a0928f
commit
8eb6f97000
1 changed files with 3 additions and 5 deletions
|
@ -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`:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue