About Lesson
Object Destructuring
Object destructuring is a concise way to extract values from objects and assign them to variables.
Syntax:
JavaScript
let { property1, property2 } = object;
Example:
JavaScript
let person = { name: "Manjeet", age: 25 };
let { name, age } = person;
console.log(name); // Output: Manjeet
console.log(age); // Output: 25
You can also assign new variable names during destructuring
Example:
JavaScript
let person = { name: "Manjeet", age: 25 };
let { name: personName, age: personAge } = person;
console.log(personName); // Output: Manjeet