Documentation

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

Sections

localStorage.getItem()

Retrieves data that was previously saved to localStorage.

const savedName = localStorage.getItem('userName');

if (savedName !== null) {
  console.log('Welcome back, ' + savedName);
} else {
  console.log('No saved name found');
}

Important:

  • Returns null if the key doesn’t exist
  • Always check for null before using the value