Comparison
localStoragevssessionStorage
localStorage
you saved the preference and it was still there a week later, on that browser only.
A synchronous key-value store of strings, scoped to the origin, with no expiry. It is convenient and it is synchronous on the main thread, which means a large read blocks rendering. It is readable by any script on the origin, so nothing sensitive belongs in it, and the accessor itself throws in some privacy modes, so every access needs wrapping.
Full entry →sessionStorage
the value survived a refresh and vanished when the tab was closed, and the other tab never saw it.
The same API as `localStorage` with a different lifetime: scoped to one tab and cleared when it closes. That per-tab isolation is the point — it is right for a multi-step flow that should not leak between tabs, and wrong for anything the user expects to persist. A duplicated tab copies the contents once and then the two diverge, which surprises people.
Full entry →