Back
Syntax
Study
Editor
Mode:
HTML
CSS
JavaScript
PHP
Reset
Run »
HTML / CSS / JS
// Store an object const prefs = { theme: "dark", fontSize: 16, notifications: true }; localStorage.setItem("prefs", JSON.stringify(prefs)); // Retrieve and parse const stored = localStorage.getItem("prefs"); const prefs2 = stored ? JSON.parse(stored) : {}; // Helper with default function getStored(key, defaultVal) { try { const val = localStorage.getItem(key); return val !== null ? JSON.parse(val) : defaultVal; } catch { return defaultVal; } }
Result
Open