Created
June 15, 2023 09:02
-
-
Save haryantowang09/a528fae441acddd251729f718b7d8649 to your computer and use it in GitHub Desktop.
Javascript with Optional chainging
This file contains 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 adventurer = { | |
name: 'Alice', | |
cat: { | |
name: 'Dinah' | |
} | |
}; | |
const dogName = adventurer.dog?.name; | |
console.log(dogName); | |
// Expected output: undefined | |
console.log(adventurer.someNonExistentMethod?.()); | |
// Expected output: undefined | |
Read More | |
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Optional_chaining |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment