Documentation

Student-friendly HTML, CSS, and JavaScript reference with examples

Sections

localStorage.setItem()

Saves data to the browser that persists even after closing the page.

// Save a name
localStorage.setItem('userName', 'Alice');

// Save a number (stored as string)
localStorage.setItem('score', '100');

Important:

  • Data is stored as strings
  • Data stays until you remove it or clear browser data
  • Each website has its own storage