open atlas
↑ Back to track
Base CS from zero CS · 06 · 07

Variables and state: multiple-choice review

Multiple-choice synthesis across the variables unit — binding vs value, assignment as a store, mutation and state, copy vs reference semantics, and aliasing traps.

CS Middle ◷ 13 min
Level
FoundationsJuniorMiddleSenior

Six questions that cut across the whole unit. Each one is a decision about what is actually stored in a cell — a value or a reference — and what changes when you assign or mutate. Get the memory model right and aliasing bugs stop being surprises.

Goal

Confirm you can connect the four ideas the unit built up: a variable is a name bound to a cell, assignment overwrites that cell, mutation changes state in place, and primitives copy while objects share by reference.

Quiz

After 'let score = 0', the program runs 'score = 42'. What changed in memory?

Quiz

Why is reading '=' as 'equals' a trap, and what should you read it as instead?

Quiz

A bug report says 'I changed obj2 and obj1 mutated on its own.' The code was 'let obj2 = obj1'. What actually happened?

Quiz

'const user = { name: "A" }; user.name = "B";' runs without error. Yet 'const x = 1; x = 2;' throws. Why?

Quiz

'let a = [1,2]; let b = a; b.push(3);' — then code elsewhere reads a.length expecting 2. Why does it see 3?

Quiz

What is the difference between a program's 'state' and the 'mutations' that produced it?

Recap

The through-line: a variable is a name bound to a cell, and the name and the value are different things. Assignment is a destructive store — ‘gets’, not ‘equals’. Mutation changes a cell in place, and state is the snapshot of all current cell contents. The decisive split is what sits in the cell: a primitive value (copied on assignment, so changes do not propagate) or a reference to a heap object (copied as an address, creating aliases where one mutation is visible through every name). const seals which reference a cell holds, never the contents behind it.

Something unclear?

Ask a question about this lesson. Questions are anonymous and go straight to the author to make the lesson better.

shortcuts expand
search
K
prev piece
k
next piece
j
cycle tier
t
this menu
?
sources2
expand
  1. 01
  2. 02

Trademarks belong to their respective owners. Editorial reference only.