What is the core difference between localStorage and sessionStorage?

WHAT IT TESTS: Tab isolation versus origin-wide persistence. ANSWER OUTLINE: sessionStorage dies with its tab; localStorage survives restarts and shares across tabs. Example: checkout form versus theme preference. RED FLAG: Claiming persistence time differs.
WHAT IT TESTS: Whether you know sessionStorage is tab- and origin-scoped, while localStorage is origin-scoped and survives restarts. ANSWER OUTLINE: First, state that sessionStorage dies with its tab and is not shared across tabs, while localStorage persists and is shared. Second, give a concrete example: store a multi-step checkout draft in sessionStorage to prevent cross-tab leaks, and store a theme preference in localStorage for global access. RED FLAG: Claiming the only difference is persistence duration while ignoring tab-level scope.
Read the original → developer.mozilla.org
- #web storage
- #localstorage
- #sessionstorage
- #frontend
Get five bites like this every day.
Tezvyn delivers a daily feed of 60-second tech bites with quizzes to lock in what you learn.