About Lesson
Working with Non-String Data
LocalStorage stores data as strings, so objects or arrays must be converted using JSON.stringify and JSON.parse.
Example: Storing an Object
JavaScript
const user = { name: "John", age: 30 };
localStorage.setItem("user", JSON.stringify(user));
const retrievedUser = JSON.parse(localStorage.getItem("user"));
console.log(retrievedUser); // Outputs: { name: "John", age: 30 }