Interview Question

What is localStorage?

localStorage keeps origin-scoped string data beyond one page session.

💡 Concept ✅ Quick Revision ⚡ JavaScript

Answer

localStorage provides origin-scoped string key/value storage through a Storage object. • Its data is shared by same-origin documents using the same storage area. • Values are stored as strings. • The API is synchronous and must not hold secrets.

Example

Code
localStorage.setItem('theme', 'dark');
console.log(localStorage.getItem('theme'));
Output
dark

Quick Revision

localStorage keeps origin-scoped string data beyond one page session.