Last active
March 4, 2020 19:43
-
-
Save thawkin3/91e89ad6e1963a4f0bc4a40c2d19d03d to your computer and use it in GitHub Desktop.
Accessing deeply nested object properties with the optional chaining operator
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| const user = { | |
| firstName: 'John', | |
| lastName: 'Doe', | |
| address: { | |
| street: '123 Anywhere Lane', | |
| city: 'Some Town', | |
| state: 'NY', | |
| zip: 12345, | |
| }, | |
| } | |
| const street = user?.address?.street | |
| // '123 Anywhere Lane' | |
| const badProp = user?.fakeProp?.fakePropChild | |
| // undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment