Skip to content

Instantly share code, notes, and snippets.

@haryantowang09
Created June 15, 2023 09:02
Show Gist options
  • Save haryantowang09/a528fae441acddd251729f718b7d8649 to your computer and use it in GitHub Desktop.
Save haryantowang09/a528fae441acddd251729f718b7d8649 to your computer and use it in GitHub Desktop.
Javascript with Optional chainging
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