SyntaxStudy
Sign Up
JavaScript Beginner 3 min read

sessionStorage Basics

sessionStorage

sessionStorage is scoped to the current browser tab session. Opening the same URL in a new tab creates a separate, empty sessionStorage.

Example
// Useful for single-session data
sessionStorage.setItem("formStep", "2");
sessionStorage.setItem("cartId", "abc-123");

// Data is lost when the tab is closed
// Each tab has its own isolated sessionStorage

// Good use cases:
// - Multi-step form progress
// - Temporary filters
// - Tab-specific state
// - Cart before login
Pro Tip

Use sessionStorage for single-visit state that should reset on a new visit, like multi-step wizard progress.