QUESTION 16 / 20 · OBJECTS · INTERMEDIATE

Missing or null?

What will this code print? Read each line, then make your prediction.

Where this matters

Defaults are useful for optional fields, but explicit null may mean something different from an absent field in your data format.

JavaScript · read-only example
const { name = 'Guest' } = {};
const { nickname = 'Guest' } = { nickname: null };
console.log(name);
console.log(nickname);
Your prediction

Read the full explanation

Destructuring defaults apply when the value is undefined. A missing name uses Guest; explicit null is preserved.

Trace the code

  1. Reading the missing name property produces undefined, which activates its default.
  2. Reading nickname produces null because that property is present with that value.
  3. 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.
Expected console output
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.