Learning object 47 of 100
Local storage inspector
Run code that saves and loads settings, see every stored key and value, and simulate a page reload to check what survives.
Loading…
What it shows
localStorage keeps string values by key across reloads; sessionStorage keeps them for one tab. getItem returns null for a missing key, and every value comes back as a string, so numbers and booleans need converting. In this sandboxed preview storage lives in memory for the page; the Simulate a page reload button runs the program again with the stored data, the way a real page would find it.
Guided experiment
- Run Visit counter, then press Simulate a page reload several times.
- In Theme, click Toggle theme in the preview and reload. Which theme is restored?
- In Strings only, explain why the muted check is wrong.
Predict
localStorage.setItem("n", 5): what does typeof localStorage.getItem("n") give?
Related
Lessons: Lesson 68: Local storage and session storage
Projects: Project 9: Shopping Cart Price Calculator
Source: web/assets/js/objects/object-047.js in the companion repository.