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.
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.
<!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