LESSON 29

Local Storage

Learning objective: Save data in the browser with localStorage.

Understand

localStorage keeps small data between visits.

localStorage.setItem saves a string by key and getItem reads it back — even after the page is closed and reopened. Use JSON.stringify and JSON.parse to store objects. This is exactly how Bynteq remembers your progress.

Analogy: localStorage is like a small notebook the browser keeps for your site between visits.

See It in Action

Saving and reading:

localStorage.setItem("name", "Sam");
const saved = localStorage.getItem("name");
console.log(saved); // Sam
How it works: The value is stored under the key 'name' and can be read back later, even after a refresh.

Try It Yourself

  1. Save a value with setItem.
  2. Refresh and read it with getItem.
  3. Store an object using JSON.stringify.

Quick Quiz

What does localStorage let you do?

Challenge

Save a user's name and greet them by it after a refresh.

Success condition: Your page remembers the name after being reloaded.