A developer is building a multi-page form wizard. They need to persist data across form steps without exposing it in the URL. What is the recommended storage mechanism for this temporary, session-scoped data?
- A.sessionStorage: it scopes data to the current browser tab and session - cleared when the tab closes, not shared between tabs. This is ideal for multi-step form wizards where data is temporary, user-specific, and should not leak between browser sessions or tabs
- B.Store in localStorage so data persists even if the browser tab is closed
- C.Store in a cookie with SameSite=Strict to prevent CSRF during form submission
- D.IndexedDB provides the best performance for form data persistence across steps
Why A is correct
sessionStorage is scoped per tab and per session - cleared when the tab closes. This makes it ideal for temporary wizard data: no risk of data leaking to other tabs (unlike localStorage which is shared within origin across all tabs), and it clears automatically on session end. Security note: sessionStorage is still accessible by JavaScript (same XSS risk as localStorage), so it should not hold highly sensitive credentials. For sensitive session data, HttpOnly server-side sessions are more appropriate.
Know someone studying for Web App Fundamentals? Send them this one.