Created
May 2, 2018 20:59
-
-
Save sarahquigley/628eaa413ffb6164f67b76f3c4a92f2a to your computer and use it in GitHub Desktop.
Example of Es6 Array Destructuring Assignment
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 cats = [ 'Maru', 'Colonel Meow', 'Grumpy Cat' ]; | |
var yayCat = cats[0], lolCat = cats[2]; | |
var tmpCat = yayCat; | |
yayCat = lolCat; | |
lolCat = tmpCat; | |
/* >= ES6 */ | |
var cats = [ 'Maru', 'Colonel Meow', 'Grumpy Cat' ]; | |
var [ yayCat, , lolCat ] = cats; | |
[ yayCat, lolCat] = [ lolCat, yayCat]; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment