Interactive Playground
Customize the shape below, then save your settings. Refresh the page to see them restored!
Learn how browsers remember your settings!
Back to TNT JS apps
Local Storage saves data directly in your web browser. Unlike regular variables that disappear when you close the page, localStorage data stays forever until you delete it!
Data is stored using keys (names) and values (the actual data). Think of it like a labeled box - the key is the label, and the value is what's inside.
localStorage can only store text (strings). To save complex data like objects, we use JSON.stringify() to convert it, and JSON.parse() to read it back.
Each website has its own separate localStorage. Data saved by one website cannot be accessed by another website - it's private to each domain.
Customize the shape below, then save your settings. Refresh the page to see them restored!
// Step 1: Collect all settings into an object
const settings = {
color: '#4CAF50',
size: 100,
shape: 'circle'
};
// Step 2: Convert object to a JSON string
const settingsString = JSON.stringify(settings);
// Result: '{"color":"#4CAF50","size":100,"shape":"circle"}'
// Step 3: Save to localStorage with a key name
localStorage.setItem('shapeSettings', settingsString);
// Step 1: Retrieve the string from localStorage
const savedString = localStorage.getItem('shapeSettings');
// Step 2: Check if data exists (returns null if not found)
if (savedString !== null) {
// Step 3: Convert JSON string back to an object
const settings = JSON.parse(savedString);
// Step 4: Use the settings
console.log(settings.color); // '#4CAF50'
}
This shows exactly what's stored in your browser right now:
(No data saved yet)