Browser Storage — localStorage, Cookies and IndexedDB — Concept Check
Questions on Browser Storage — localStorage, Cookies and IndexedDB. Four options with different lifetimes, sizes and security properties. The choice that matters most is where an auth token goes, and the answer is usually not localStorage.
Questions in this quiz
8 questions on Browser Storage — localStorage, Cookies and IndexedDB — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer stores a JWT in localStorage for authentication. What is a major security risk of this approach?
- ASusceptible to CSRF attacks
- BRequires serialization of objects
- CVulnerable to XSS attacks
- DLimited to 5MB storage
2.A web application uses sessionStorage to save user preferences. What happens when the user closes the tab?
- AData is saved to localStorage
- BData persists across tabs
- CData is sent to the server
- DData is cleared
3.Which storage option should be used for storing large, structured data in a web application?
- AlocalStorage
- BCookies
- CsessionStorage
- DIndexedDB
4.A developer sets a token in an httpOnly cookie. What is a benefit of this approach compared to localStorage?
- ALarger storage capacity
- BImmune to XSS theft
- CEasier cross-origin access
- DSimpler API usage
5.Why might a developer choose localStorage over Cookies for storing non-sensitive data?
- ALarger storage capacity
- BData sent with every request
- CBetter security
- DAutomatic data synchronization
6.A service worker caches HTTP responses using the Cache API. What is a primary advantage of this?
- ASimplified data structure
- BOffline access to resources
- CIncreased storage capacity
- DImproved security
7.What happens if you try to store an object directly in localStorage without serialization?
- AStores as null
- BThrows an error
- CStores as [object Object]
- DConverts to JSON automatically
8.A developer mistakenly believes that sessionStorage data is shared across all tabs. What is the correct behavior?
- AData is shared across tabs
- BData is accessible by server
- CData is isolated to each tab
- DData persists after browser restart