Created
May 22, 2020 13:08
-
-
Save silent1mezzo/f7d892aa9bca95c06db3dbfe9fdc4175 to your computer and use it in GitHub Desktop.
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' | |
} | |
}; | |
// Before Optional Chaining | |
if(adventurer && adventurer.cat){ | |
console.log(adventurer.cat.name); | |
//'Dinah' | |
} | |
// After Optional Chaining | |
console.log(adventurer.cat?.name); | |
//'Dinah' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment