QUESTION 15 / 20 · OBJECTS · BEGINNER

A new outer object

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

Where this matters

Object spread can produce an updated record without changing the original top-level values. Property order matters when names repeat.

JavaScript · read-only example
const first = { score: 1 };
const second = { ...first, score: 2 };
console.log(first.score);
console.log(second.score);
Your prediction

Read the full explanation

Spread creates a new object. The later score property overrides the copied value only on second.

Trace the code

  1. Spreading first copies its score value into a new object.
  2. The later score property replaces the copied score on that new object.
  3. The earlier object is still separate and still holds its original number.

Why the other predictions differ

  • 1 1 — The explicit score after spread replaces the copied score.
  • 2 2 — Overriding a property on the new object does not mutate first.
Expected console output
1
2

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

Change one thing

Reverse the property order so the spread comes last.

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 first = { score: 1 }; const second = { score: 2, ...first }; console.log(second.score);
Check the variation’s output
1

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