JavaScript · Junior · Question 28 of 75

What does this code print?

const { name = "Guest", age } = { age: 30 };
console.log(name, age);

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.

Further reading

Problem with a question

JavaScript · Junior · question 28

Test yourself

Take the JavaScript · Junior quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz