Student-friendly HTML, CSS, and JavaScript reference with examples
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:
null if the key doesn’t exist null before using the value