Destructuring with Default Quiz
Question
What is the value of `port` after `const { port = 3000 } = { host: 'localhost' }`?
Hint
Default values in destructuring are used when the property is undefined.
Explanation
When destructuring, a default value is used if the property is undefined or absent. The object { host: 'localhost' } has no port property, so port takes the default value 3000. If the object had port: undefined, the default would also apply. If it had port: 8080, the default would not apply.
Related Resources
Related Lessons
- JavaScript Objects
Learn about destructuring defaults.
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.