Created
August 24, 2020 11:39
-
-
Save yano3nora/78e0777708af7d57bb31bedae093bce1 to your computer and use it in GitHub Desktop.
[js: Optional Chaining] いわゆる null セーフな . チェイン。 #js
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
// IE 非対応なので polyfill or babel で頑張る必要ある | |
// https://developer.mozilla.org/ja/docs/Web/JavaScript/Reference/Operators/Optional_chaining | |
const adventurer = { | |
name: 'Alice', | |
cat: { | |
name: 'Dinah' | |
} | |
}; | |
const dogName = adventurer.dog?.name; | |
console.log(dogName); | |
// expected output: undefined |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment