playground
Any program in the subset
Nothing here is graded or recorded. Write something, step it, and watch what the machine does with it.
← → to step, Home and End for the ends
Program
1const base = { tags: [] };23function withTag(options, tag) {4const merged = { ...base, ...options };5merged.tags.push(tag);6return merged;7}89const a = withTag({ name: "a" }, "first");10const b = withTag({ name: "b" }, "second");11console.log(a.tags.length, b.tags.length, a.tags === b.tags);
Scope chain
no scope entered yet
Call stack
- (top level)
Heap
no objects yet
Trace
- 1enter scope, creating base, a, b, withTag
- 2allocate array(0)
- 3allocate object
- 4base = object
- 5read withTag
- 6allocate object
- 7call withTag
- 8enter scope, creating merged
- 9read base
- 10read options
- 11allocate object
- 12merged = object
- 13read merged
- 14read tags
- 15read push, found on the prototype — the own object does not have it; the lookup walked the prototype chain
- 16read tag
- 17read merged
- 18return object
- 19a = object
- 20read withTag
- 21allocate object
- 22call withTag
- 23enter scope, creating merged
- 24read base
- 25read options
- 26allocate object
- 27merged = object
- 28read merged
- 29read tags
- 30read push, found on the prototype — the own object does not have it; the lookup walked the prototype chain
- 31read tag
- 32read merged
- 33return object
- 34b = object
- 35read console
- 36read log
- 37read a
- 38read tags
- 39read length
- 40read b
- 41read tags
- 42read length
- 43read a
- 44read tags
- 45read b
- 46read tags
- 47console.log: 2 2 true
Output
nothing logged yet