freecoding.school100% FREE · NO SIGNUP
Await StationISSUE #18 of 26

localStorage · key-value persistence

PromissaVSRace Condition Rex
Promissa sayslocalStorage persists string key–value data on the device until explicitly cleared.

localStorage.setItem(key, value) / getItem / removeItem / clear store strings that survive reloads and restarts. For objects, JSON.stringify in and JSON.parse out. It's synchronous, ~5-10MB per origin, and readable by any script on the page — perfect for prefs and drafts, never for secrets or tokens.

Power-ups you unlock

Race Condition Rex attacks — common mistakes

Boss battlePersist a settings object across reloads with JSON.stringify/parse.

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>const s=JSON.parse(localStorage.getItem('s')||'{"n":0}');s.n++;localStorage.setItem('s',JSON.stringify(s));
document.getElementById('o').textContent='reloads: '+s.n;</script></body></html>
▶ Open the interactive comic issue
‹ Message Channel · Structured CloningSessionStorage · Tab-Scoped ›