1. Introduction
Modern websites need to store data:
- User preferences (theme, language)
- Login status
- Shopping cart items
- App state between page reloads
JavaScript provides Web Storage APIs and JSON to store and exchange data efficiently.
2. Web Storage in JavaScript
Web Storage allows browsers to store data locally on the user’s device.
Types of Web Storage
- localStorage
- sessionStorage
Both store data as key–value pairs (strings only).
3. localStorage
What is localStorage?
- Stores data permanently
- Data remains even after:
- Browser restart
- Computer restart
- Cleared only by:
- Code
- User manually clearing browser data