Skip to content

Instantly share code, notes, and snippets.

@pjcodesjs
Last active May 11, 2021 19:59
Show Gist options
  • Save pjcodesjs/4d5185a9266fa76b201791f54c002ce2 to your computer and use it in GitHub Desktop.
Save pjcodesjs/4d5185a9266fa76b201791f54c002ce2 to your computer and use it in GitHub Desktop.
// OPTIONAL CHAINING EXAMPLE
let character = {
name: 'Dean Winchester',
age: 34,
car: 'Chevy Imala (Baby)',
enemy_demons: [ 'Abadon', 'Yellow Eyes', 'Crowley' ],
enemy_angels: [ 'Zacharia', 'Michael', 'Lucifer' ],
family: {
mother: 'Mary',
father: 'John',
brother: 'Sam',
}
}
const friend = character.friend?.name;
console.log(friend) // undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment