freecoding.school100% FREE · NO SIGNUP
Script SpringsISSUE #16 of 29

operators · assignment · += · -= · ??=

SparkyVSNaN the Trickster
Sparky saysAssignment operators combine an operation with assignment: += -= *= and logical ??= ||= &&=.

x += 5 is x = x + 5; the same pattern covers -= *= /= %=. The logical-assignment trio is newer: a ??= b assigns only if a is null/undefined, a ||= b if falsy, a &&= b if truthy. They tidy up common default-setting patterns.

Power-ups you unlock

NaN the Trickster attacks — common mistakes

Boss battleDefault a config value with ??= only when it’s undefined.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>let cfg={}; cfg.theme ??= 'dark'; cfg.theme ??= 'light';
document.getElementById('o').textContent='theme = '+cfg.theme;</script></body></html>
▶ Open the interactive comic issue
‹ Operators · ArithmeticOperators · Comparison · == Vs === ›