1.3 — Reassignment
Variables would be pointless if they couldn’t change — a score that can’t go up isn’t much of a score. Changing what a variable remembers is called reassignment, and it hides a line that breaks every math-trained brain on first sight: score = score + 5. In math class that’s impossible. In JavaScript it’s the single most common move in all of programming. Let’s fix your intuition permanently.
let score = 10; score = score + 5; console.log(score);
Line 1 you can already narrate in your sleep: box borrowed, 10 placed inside, label “score” tied on. (Drawn in one go — you’ve earned the shortcut.)
The deeper story, with the real names for things — this part is what turns “I saw it” into “I can explain it.”
The = sign is the assignment operator, and the golden rule is: right side first, completely, then store left.
The left side isn’t a value at all — it’s a destination (which box to fill). That’s why 10 = score is an error: 10 isn’t a box.
Programmers hear “score gets 15” in their heads, never “score equals 15”. Adopt that reading today, and the confusion never returns. (The “does it equal?” question uses different symbols, ===, coming in lesson 1.9.)
The read-change-store pattern is so common that JavaScript ships shortcuts: score += 5 is exactly score = score + 5, and score++ adds 1. They do nothing new — same box, same label, new contents. Learn the long form first (you just did). Then treat the shortcuts as abbreviations, not magic.
One boundary worth knowing early: reassignment only works on variables declared with let. If score had been declared with const (“constant” — a label welded on), line 2 would throw TypeError: Assignment to constant variable — an error you can now read fluently. The full let-vs-const decision is the very next lesson.
⌨️ a sentence that grows
You watched score = score + 5 with numbers — now do the same read-change-store move with TEXT: one variable, growing itself twice.
requirements:
- A variable named
sentencestarts as"I". - Grow it twice using ITSELF on the right side — first to
"I love", then to"I love JS". Each step must read the current value and add to it:sentence = sentence + …— retyping the whole text is not allowed. - ONE
console.log(sentence)at the very end. (Mind the spaces — they have to come from the added pieces.)
when you press RUN, the console must show exactly:
✏️ Quick check 1
Type what ends up in count’s box:
let count = 3; count = count * 2;
✏️ Quick check 2
How should you read the = symbol out loud? Type the one word.
✏️ Quick check 3
Trace it box-by-box, then type the final value of total:
let total = 100; total = total - 30; total = total - 30;
🗣️ Now teach it back
Your friend says “score = score + 5 is impossible — nothing can equal itself plus 5!” Set them straight: what does = really mean, and what happens step by step?
Write it as if your friend is sitting next to you. Saved to your journal — future-you will use these notes to teach others.