Retrieves a value from localStorage by its key and parses it as JSON.
Contributed by @ditinagrawal
function getFromLocalStorage(key) {
const item = localStorage.getItem(key);
return item ? JSON.parse(item) : null;
}
getFromLocalStorage("user"); // { name: "John", age: 30 }