The localStorage object stores data in browser memory with no expiration date.
The localStorage allows us to save the key/value pairs in a web browser
Example :
// Store
localStorage.setItem("Company", "Revolution IT Solutions");
// Retrieve
let company = localStorage.getItem("Company");
console.log(company);
//check log in browser for output
Only strings can be stored with localStorage or sessionStorage, but we can use JSON.stringify to
store more complex objects and JSON.parse to read them.
JSON - JavaScript Object Notation is a standard text-based format for representing structured data based on JavaScript object syntax. It is commonly used for transmitting data in web applications
Example :
// Create object:
let student = { rollno: 71, standard: 10 };
localStorage.setItem(key, JSON.stringify(student));
// Read Object:
let item = JSON.parse(localStorage.getItem(student));
console.log(item);
//check log in browser for output