Skip to the workspace
Pebellslearn by building
Data Types  ›  Lesson

Objects

Object 12 min

javascript / Objects

Explore each scene at your own pace.

01 · Objects

Objects

Objects

An object groups properties under keys. A property holds a value, and multiple variables can refer to the same object.

A record keeps an article’s related data together; copying its reference does not copy the record.

See the mechanism

Walk through the modelObjectsAuthored snapshots of the example; use Run below to test the code.
articleobject A
A.savedfalse
The object has its own identity.
1 of 3

Follow one example

javascript

Both bindings refer to one object. Updating saved through sameArticle is visible through article. const prevents rebinding article, not changing its writable properties. A missing property normally reads as undefined. A new object literal creates a distinct object even when its properties look identical. Destructuring extracts the title property. Object spread makes a shallow copy with saved replaced; nested objects would still be shared. Optional chaining stops a property access when its receiver is null or undefined, and ?? supplies the missing-author fallback.

Predict, change and check

Predict: If sameArticle is replaced with a separate literal containing the same fields, does the update still reach article?

Test your explanation: Try the separate literal and compare === and saved. Draw two objects instead of one to explain the changed outcome.

The tasks below ask you to explain that result and apply the idea to different inputs.

Apply and distinguish

References are values too

Assigning an object to a second variable copies the reference value, not a recursively independent record. Changing a field through one reference is visible through another reference to the same object. Reassigning one variable to a new object does not retarget the other variable.

Object spread creates a new outer object but nested object references can remain shared. Decide whether a feature needs shared state, a shallow copy, or a deeper cloning strategy and document which value types are supported. Object identity comparisons do not recursively compare fields; two records can look identical while remaining distinct objects.

Check your understanding: State the input contract, identify the operation that changes the result, and give one boundary input that would distinguish the correct rule from the mistake described above.

Scene 1 of 2
Project context and further resources
Additional resources
Hover to wake the cannons. Drag to move, or use arrow keys when focused. Press Enter to fire a shot.