HTML5 Web Storage

Level : Advanced
Mentor: Shailendra Chauhan
Duration : 00:00:30

localStorage object:

The localStorage object stores data with no expiration date, making it persist even after the browser is closed. This data is accessible across browser sessions and tabs.


// Storing data
localStorage.setItem("username", "JohnDoe");
// Retrieving data
const username = localStorage.getItem("username");
console.log(username); // Outputs: "JohnDoe"

sessionStorage object:

The sessionStorage object is similar to localStorage but stores data for only one session, which means the data is cleared when the user closes the specific browser tab or window.


// Storing session data
sessionStorage.setItem("theme", "dark");
// Retrieving session data
const theme = sessionStorage.getItem("theme");
console.log(theme); // Outputs: "dark"
Self-paced Membership
  • 22+ Video Courses
  • 800+ Hands-On Labs
  • 400+ Quick Notes
  • 55+ Skill Tests
  • 45+ Interview Q&A Courses
  • 10+ Real-world Projects
  • Career Coaching Sessions
  • Email Support
Upto 60% OFF
Know More
Still have some questions? Let's discuss.
Accept cookies & close this