DOM & browser APIs · Trade-off
Storage options: cookies vs localStorage vs sessionStorage vs IndexedDB
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voiceThe interviewer asks
Compare cookies, localStorage, sessionStorage and IndexedDB. Where would you store a cart, a JWT, user preferences, and 50 MB of offline data?
Then
Follow-ups the interviewer asks next
- Size limits and sync vs async (localStorage blocks the main thread).
- Cookie attributes:
HttpOnly,Secure,SameSite,Domain,Path,Partitioned. - The
storageevent for cross-tab sync. - Safari ITP eviction of script-written storage, and storage quotas or
navigator.storage.persist().
The answer
What a strong answer covers
- Cookies (about 4 KB, sent with every request, can be HttpOnly); localStorage (about 5 MB per origin, strings, persistent, sync); sessionStorage (per tab); IndexedDB (large, async, structured, available in workers)
- None of the script-accessible stores are safe from XSS
- Cache API for request/response pairs (service workers)
The red pen
Common traps
Avoid:"localStorage is secure because it's per-domain".
Practise this out loud
Say your answer out loud to an AI interviewer that follows up, and get a score for it.
Practise by voicePractise questions like this out loud
Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.