localStorage.getItem() Read data
Last updated: 2026-09-09
localStorage.getItem() Read data
getItem reads a value from localStorage by key. Returns null if the key doesn't exist.
| Category | Browser (BOM) |
|---|---|
| ES version | DOM |
📝 Syntax
const value = localStorage.getItem('key');
⚙️ Parameters
| key | The storage key. |
|---|
Returns:The stored string value, or null.
Mutates the original:No (returns a new value)
▶ Example
Edit the code, press Run, and see the result in the output panel:
Output:
Zhang
Zhang
null
💡 Tip Check for null before JSON.parse — the key may not exist on first visit.
ℹ️ info Values are always strings — use Number() to convert.
🌐 Browser support
| Browser | |||||
|---|---|---|---|---|---|
| localStorage.getItem() | ✓ v1 | ✓ v12 | ✓ v1 | ✓ v1 | ✓ v1 |
| Supported by all modern browsers | |||||
🏷️ Related Items
💡 Related Cases
More case studies coming soon — check back later.
📚 Related Tutorials
❓ FAQ
Qt
Ar
Qs
An