localStorage is a Web Storage API in JavaScript that allows developers to store key-value pairs in a web browser. This data persists even after the browser is closed and reopened, making it useful for saving user preferences, game scores, or any other data that needs to be retained across sessions.
localStorage is part of the larger Web Storage API, which also includes sessionStorage. The key difference is that data stored in localStorage has no expiration time, while sessionStorage data is only available during the page session.
localStorage can only store strings, but you can store objects as JSON strings by using `JSON.stringify()` and retrieve them back using `JSON.parse()`.
// Store data in localStorage
localStorage.setItem('username', 'JohnDoe');
// Retrieve data from localStorage
var user = localStorage.getItem('username');
// Remove data from localStorage
localStorage.removeItem('username');
// Clear all localStorage
localStorage.clear();
How do I avoid rehashing overhead with std::set in multithreaded code?
How do I find elements with custom comparators with std::set for embedded targets?
How do I erase elements while iterating with std::set for embedded targets?
How do I provide stable iteration order with std::unordered_map for large datasets?
How do I reserve capacity ahead of time with std::unordered_map for large datasets?
How do I erase elements while iterating with std::unordered_map in multithreaded code?
How do I provide stable iteration order with std::map for embedded targets?
How do I provide stable iteration order with std::map in multithreaded code?
How do I avoid rehashing overhead with std::map in performance-sensitive code?
How do I merge two containers efficiently with std::map for embedded targets?