The sessionStorage object is a companion to localStorage within the Web Storage API. While it shares an identical method interface (setItem, getItem, removeItem, clear), its lifecycle and scoping rules are strictly bounded by the browser tab session.
| Feature | sessionStorage | localStorage |
|---|---|---|
| Data Lifetime | Cleared immediately when the browser tab/window is closed | Persists indefinitely until explicitly deleted |
| Scope Boundary | Scoped strictly to the specific browser tab and origin | Shared across all tabs, windows, and iframes of same origin |
| New Tab Behavior | Opening a new tab creates a fresh, empty session | New tab accesses identical existing data |
| Capacity | Typically 5MB per origin | Typically 5MB–10MB per origin |
| Storage API | setItem, getItem, removeItem, clear | setItem, getItem, removeItem, clear |
The syntax for sessionStorage is identical to localStorage:
sessionStorage survives normal page refreshes and page restorations!Ctrl + click on tab) copies the current session storage snapshot into the new tab, but from that point forward they are completely isolated.Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| LocalStorage | Practical Use Cases |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.
Practice in live mentor-led sessions with real projects, mock tests, and verifiable certification at MSK Institute.