Javascript: Destructuring
It allows us to write more understandable code, so in function definition we see which properties are actually using.
Object destructuring
const person = {
name: 'Max',
age: 29,
greet() {
console.log('Hi. I am ' + this.name);
}
};
const printName = ({ name, age }) => {
console.log(name + age);
}
printName(person);
/////////////////////
const { name, age } = person; //this will create two new constants
Array destructuring
const hobbies = ['Sports', 'Cooking'];
const [hobby1, hobby2] = hobbies;
console.log(hobby1, hobby2);