QUESTION 14 / 20 · OBJECTS · INTERMEDIATE

Look one level deeper

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

Where this matters

Copying settings with spread separates the outer record, but nested settings still need attention when you want independent edits.

JavaScript · read-only example
const original = { settings: { theme: 'light' } };
const copy = { ...original };
copy.settings.theme = 'dark';
console.log(original.settings.theme);
Your prediction

Read the full explanation

Spread copies the outer object. Both settings properties still reference the same nested object, whose theme is changed.

Trace the code

  1. The outer copy is a different object from original.
  2. The settings reference is copied as a property value; the nested object itself is not copied.
  3. Both paths reach that nested object, so changing its theme is visible through original.

Why the other predictions differ

  • light — A shallow spread does not duplicate nested objects.
  • undefined — The settings property exists on both outer objects.
Expected console output
dark

Reading this explanation does not record mastery. A correct submitted attempt can do so, including after review.

Change one thing

Copy the settings object as well, then change the copied theme.

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 original = { settings: { theme: 'light' } }; const copy = { ...original, settings: { ...original.settings } }; copy.settings.theme = 'dark'; console.log(original.settings.theme);
Check the variation’s output
light

Explain which binding, value, or operation changed before moving to the next challenge.