Object Destructuring Assignment

 Object Destructuring Assignment


Object destructuring assignment allows you to extract values from objects and assign them to variables with a concise syntax.



const person = {

  name: 'John Doe',

  age: 30,

  address: {

    street: '123 Main St',

    city: 'New York'

  }

};


const { name, age, address: { city } } = person;


console.log(name, age, city);

// Output: John Doe 30 New York

In the example above, object destructuring is used to extract the name, age, and city properties from the person object. The address property is further destructured to extract the city property from the nested object.

No comments:

Post a Comment

The Importance of Cybersecurity in the Digital Age

 The Importance of Cybersecurity in the Digital Age Introduction: In today's digital age, where technology is deeply intertwined with ev...