Created
July 25, 2017 02:07
-
-
Save prof3ssorSt3v3/f2c26e4c9e66cd417d980879271e859f to your computer and use it in GitHub Desktop.
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
// ES6 Destructuring | |
//extracting values from objects and arrays | |
//and assigning them to multiple variables | |
let name, id, nm, num, star, planet, rest; | |
let personObj = {name:"Arthur Dent", id:42, planet:'Earth'}; | |
let personArr = ["Zaphod", 123, 'Betelgeuse']; | |
//[nm, num] = personArr; | |
//console.log(nm, num); | |
//[nm, ,star] = personArr; | |
//console.log(nm, star); | |
//[nm, ...rest] = personArr; | |
//console.log(nm, rest.length, rest[1]); | |
//({planet, name} = personObj); | |
//console.log(name, planet); | |
const f = ({id, planet, name, star='Sol'}) => { | |
console.log(name, id, planet, star); | |
} | |
f(personObj); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment