LocalStorage
ELI5 — The Vibe Check
LocalStorage is a simple key-value storage built into every browser that persists even after you close the tab. It's like a tiny notebook your website can write in. Perfect for remembering user preferences, theme choice, or a small shopping cart. Just don't put passwords in there.
Real Talk
LocalStorage is a Web Storage API that provides synchronous key-value storage in the browser with no expiration. Data persists across sessions and is scoped to the origin. Maximum size is ~5-10MB. Because it's synchronous and blocking, avoid large read/write operations that could cause jank.
Show Me The Code
// Save user preference
localStorage.setItem('theme', 'dark')
// Read it back
const theme = localStorage.getItem('theme') // 'dark'
// Remove it
localStorage.removeItem('theme')
// Clear everything
localStorage.clear()
When You'll Hear This
We store the selected language in localStorage.,LocalStorage is synchronous — don't write huge objects to it.,Clear localStorage in tests to avoid state bleed between test runs.
Related Terms
Cookie
A cookie is a tiny piece of data the server tells your browser to store and send back on every future request.
IndexedDB
IndexedDB is a full-on database living inside your browser.
SessionStorage
SessionStorage is just like LocalStorage except it forgets everything when you close the browser tab.