Created
May 2, 2018 21:05
-
-
Save sarahquigley/5bce984b4b92827a8a394121eb3d01ce to your computer and use it in GitHub Desktop.
Example of ES6 Object Destructuring Assignment - Deeply Nested Objects
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
/* ES5 */ | |
var catMaru = { | |
name: 'Maru', | |
appearance: { | |
mittens: true, | |
coat: 'tabby' | |
} | |
}; | |
var name = catMaru.name; | |
var color = catMaru.appearance.coat; | |
/* >= ES6 */ | |
var catMaru = { | |
name: 'Maru', | |
appearance: { | |
mittens: true, | |
coat: 'tabby' | |
} | |
}; | |
var { name, appearance: { coat } } = catMaru; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment