Assignment Operators
In short: = always overwrites. Compound operators like +=, -=,
*= update a variable using its own current value —
score += 5 means score = score + 5. Two newer operators only assign
conditionally: ||= fills a variable in whenever it's falsy (0, "",
false, null, undefined), while ??= fills it in only when it's
null or undefined. That difference matters the moment a falsy-but-
valid value, like 0, is a value you want to keep.

Add points to a running score
+= is shorthand for "take the current value, do the operation, assign it
back" — it reads and writes the same variable in one step:
score += 5 is exactly score = score + 5, so score becomes 15. Every
arithmetic operator has this shorthand: -=, *=, /=, %=, **=.
Fill in a missing nickname
||= only assigns when the current value is falsy — it leaves a
truthy value alone:
name starts as "", an empty string, which is falsy — so ||= replaces
it with "Guest". If name had already held "Asha", a truthy string,
||= would have done nothing at all.
The trap: a muted volume treated as unset
0 is a perfectly valid, intentional value — but it's also falsy, which
is exactly where ||= goes wrong and ??= is the fix:
vol ||= 50 treats the deliberately-muted 0 as "nothing set" and
overwrites it with 50 — the user's mute is lost. vol2 ??= 50 only
checks for null/undefined, and 0 is neither, so vol2 correctly
stays 0. Whenever 0, "", or false are meaningful values you want to
preserve, reach for ??=, not ||=.
Quick practice
What does let score = 10; score += 5; console.log(score); print?
What does let name = ""; name ||= "Guest"; console.log(name); print?
What does let vol = 0; vol ||= 50; console.log(vol); print?
What does let vol = 0; vol ??= 50; console.log(vol); print?
Which operator only assigns when the left side is null or undefined?
🎯 Your turn
A volume slider starts at 0 (muted). Code runs volume ||= 50; to set a
default when nothing has been chosen yet. Explain what goes wrong, and
rewrite it so a genuine 0 is preserved.
Write your explanation and submit it — there's no code to run here, just your reasoning.
