Created
June 13, 2016 16:41
-
-
Save syntacticsugar/b2fb986b3c1fc580fa72ba1756a33361 to your computer and use it in GitHub Desktop.
The destructuring assignment syntax is a JavaScript expression that makes it possible to extract data from arrays or objects into distinct variables.
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
var a, b, rest; | |
[a,b] = [1,2]; | |
console.log(a); // 1 | |
console.log(b); // 2 // wow, so convenient! will I remember to do this, or not bother? | |
[a, b, ...rest] = [1, 2, 3, 4, 5]; | |
console.log(a); // 1 | |
console.log(b); // 2 | |
console.log(rest); // [3, 4, 5] // incredible... although now I'm thinking this is nearly illegible for other developers | |
({a, b} = {a:1, b:2}) | |
console.log(a); // 1 | |
console.log(b); // 2 | |
({a, b, ...rest} = {a:1, b:2, c:3, d:4}); //ES7 - not implemented in Firefox 47a01 | |
var x = [1, 2, 3, 4, 5]; | |
var [y, z] = x; | |
console.log(y); // 1 | |
console.log(z); // 2 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment