Fix typo
This commit is contained in:
parent
0da5b2b68c
commit
8613348076
1 changed files with 1 additions and 1 deletions
|
@ -124,7 +124,7 @@ user2.admin?.();
|
||||||
|
|
||||||
Here, in both lines we first use the dot `.` to get `admin` property, because the user object must exist, so it's safe read from it.
|
Here, in both lines we first use the dot `.` to get `admin` property, because the user object must exist, so it's safe read from it.
|
||||||
|
|
||||||
Then `?.()` checks the left part: if the user exists, then it runs (for `user1`). Otherwise (for `user2`) the evaluation stops without errors.
|
Then `?.()` checks the left part: if the admin function exists, then it runs (for `user1`). Otherwise (for `user2`) the evaluation stops without errors.
|
||||||
|
|
||||||
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.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue