//Destructuring arrays
let numbers = [1, 2, 3];
// set the variable names on the left of the equals sign; reference the array on the right
let [a, b] = numbers;
console.log(a);
console.log(b);
//use destructuring to swap variable values from arrays all in one line
let a = 5;
let b = 10;
//swap var values here
[b, a] = [a, b];
console.log(a, b);
//destructuring using objects, note the alias!
let obj = {
name: "Rich",
age: 39,
greet() {
console.log("hola!");
}
};
//when destructuring an object use curly braces instead of brackets
let { name, greet: hello } = obj;
hello();