Say you have an object with some properties:
const person = {
firstName: 'Tom',
lastName: 'Cruise',
actor: true,
age: 57
}
You can extract just some of the object properties and put them into named variables:
const { firstName, age } = person
Now we have 2 new variables, firstName
and age
, that contain the desired values:
console.log(firstName) // 'Tom'
console.log(age) // 54
#javascript #destructuring #programming