A 6-million-character note into localStorage: what happens? Measure the room left, read estimate() and persisted(). An interactive Storage Limits & Quota…
Why it matters
A real bug: an app keeps too much in localStorage, then setItem throws and a feature quietly breaks. Knowing the limit, why try/catch is a must, when to move to IndexedDB, and that site data can be evicted, makes storage that does not burst.
The key idea
A small shelf per origin, a big shared granary, and both can be evicted
Common mistakes
setItem without try/catch Past the limit, setItem throws QuotaExceededError and a feature can break. Wrap it in try/catch and have a fallback.
Keeping big data in localStorage Only a few million characters per origin, and synchronous (it blocks the page). Big data or objects go to IndexedDB: asynchronous, with a far bigger quota.
Assuming localStorage is permanent Best-effort site data can be evicted when the disk runs low. For important data, ask for navigator.storage.persist() or make the server the source of truth.
Try it in this playground
Keep 6 million characters without try/catch QuotaExceededError stops the program.
Measure the room left on the jar shelf The browser tries until it refuses; every try is removed again.
Read the quota from estimate() Far bigger than the jar shelf.
Keep a 6-million-byte note in IndexedDB The archive cabinet takes it whole.