Where this matters
Defaults are useful for optional fields, but explicit null may mean something different from an absent field in your data format.
const { name = 'Guest' } = {};
const { nickname = 'Guest' } = { nickname: null };
console.log(name);
console.log(nickname);Read the full explanation
Destructuring defaults apply when the value is undefined. A missing name uses Guest; explicit null is preserved.
Trace the code
- Reading the missing name property produces undefined, which activates its default.
- Reading nickname produces null because that property is present with that value.
- Destructuring does not treat all falsy values as missing.
Why the other predictions differ
Guest Guest— Null does not trigger a destructuring default.undefined null— The missing name triggers the authored default.
Guest null
Reading this explanation does not record mastery. A correct submitted attempt can do so, including after review.
Change one thing
Supply an empty string and observe that it is preserved instead of replaced.
Predict the result, then run this self-contained snippet in your browser’s developer console. It uses only sample values and makes no network requests.
const { name = 'Guest' } = { name: '' }; console.log(JSON.stringify(name));Check the variation’s output
""
Explain which binding, value, or operation changed before moving to the next challenge.