QUESTION 08 / 20 · OBJECTS · BEGINNER

Two matching objects

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

Where this matters

Two separately loaded records can contain the same fields without being the same object. Compare specific fields when that is your intended question.

JavaScript · read-only example
console.log({ id: 1 } === { id: 1 });
Your prediction

Read the full explanation

Each object literal creates a separate identity. Strict equality does not compare object contents recursively.

Trace the code

  1. Each pair of braces creates a fresh object.
  2. Strict equality checks whether both operands refer to the same object, not whether their id properties match.
  3. No recursive property comparison takes place.

Why the other predictions differ

  • true — Matching properties do not make separate objects the same object.
  • TypeError — Comparing object references is valid JavaScript.
Expected console output
false

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

Change one thing

Store one object and give it a second name, then compare those references.

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

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