Building Your Learning Module...
Getting things ready for you!
Find videos you like?
Save to resource drawer for future reference!
The Web Storage API provides two mechanisms for storing data in the browser: localStorage and sessionStorage. Both store data as key-value pairs and provide a simple API for data persistence.
| Method | Description | Example |
|---|---|---|
setItem(key, value) | Store data | localStorage.setItem('user', 'John') |
getItem(key) | Retrieve data | localStorage.getItem('user') |
removeItem(key) | Delete specific item | localStorage.removeItem('user') |
clear() | Delete all items | localStorage.clear() |
key(index) | Get key by index | localStorage.key(0) |
JSON.stringify() and JSON.parse() for objects and arrays.Use JSON methods to handle complex data types
Save and restore user theme selection
The storage event fires when storage is modified in another tab/window. This allows you to sync data across multiple tabs.
Sync data between browser tabs
Easy-to-use key-value storage interface
Persistent storage across sessions
Temporary storage per tab/window
Store complex objects with JSON methods