Web Storage allows you to store data in the user's browser. Local Storage persists until explicitly deleted, while Session Storage is cleared when the browser is closed.
Local Storage can be used to store simple data as key-value pairs:
// Store data
localStorage.setItem("name", "John");
// Retrieve data
let name = localStorage.getItem("name");
console.log(name); // Outputs: John
// Remove data
localStorage.removeItem("name");
// Clear all data
localStorage.clear();
Store your name and age in Local Storage and retrieve it to display on the page.
localStorage.clear()
?Answers: Local Storage persists, Session Storage does not; use setItem()
; clears all stored data.