JavaScript · Junior · Question 28 of 75
What does this code print?
const { name = "Guest", age } = { age: 30 };
console.log(name, age);- ✓Correct answer:
Guest 30 - 2
undefined 30 - 3
TypeError
Explanation
Destructuring extracts properties into variables, and the default value is used when the property is undefined. You can rename ({ name: userName }) and destructure nested objects and arrays.