When we reload a website, JavaScript variables disappear; that’s because the web is stateless by default so the browser doesn’t remember anything once the page is refreshed. But what if you want your site to remember user preferences, saved items, or a theme choice?

That’s where localStorage comes in.

💡 What Is localStorage?

It is part of the Web Storage API, which lives in the Window object, meaning it’s only available in browser JavaScript (not Node.js).

Key features:

  • Data persists even after closing the browser
  • Storage limit: around 5–10 MB (varies by browser)
  • Accessible only by JavaScript running on the same domain
  • Stores data as strings only

🎯 Why Use localStorage?

✔️ It’s great for small, persistent, non-sensitive data such as:

  • Theme…

Similar Posts

Loading similar posts...

Keyboard Shortcuts

Navigation
Next / previous item
j/k
Open post
oorEnter
Preview post
v
Post Actions
Love post
a
Like post
l
Dislike post
d
Undo reaction
u
Recommendations
Add interest / feed
Enter
Not interested
x
Go to
Home
gh
Interests
gi
Feeds
gf
Likes
gl
History
gy
Changelog
gc
Settings
gs
Browse
gb
Search
/
General
Show this help
?
Submit feedback
!
Close modal / unfocus
Esc

Press ? anytime to show this help