2.
How do you destructure an object in JavaScript?
By using the object literal syntax { } and specifying the desired properties inside.
By using the spread operator ... followed by the object name.
By assigning the desired properties of the object to variables with the same names.
By using the destructuring assignment syntax with the object name followed by curly braces { }.
Correct: D
To destructure an object in JavaScript, you use the destructuring assignment syntax with the object name followed by curly braces { }. Inside the curly braces, you specify the desired properties of the object that you want to extract and assign to variables. Example:
var person = {
firstname: 'Jon',
lastname: 'Doe'
};
var { firstname, lastname} = person;
console.log( firstname, lastname);