localStorage in Javascript

Share Button

Introduction

localStorage is used in javascript for storing data in clients side i.e. in the browser of user. There is no expiration time in localStorage that means the data stored in localStorage will not destroyed after closing or restarting the browser.

 

Usage

For storing data in localStorage use this syntax

localStorage.setItem('something', 'Daves');

For getting this stored data use this syntax

localStorage.getItem('something');

For deleting an specific item from localstorage use this

localStorage.removeItem('something');

For deleting all localstorage data use this

localStorage.clear();

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
localStorage 4 3.5 8 10.50 4
sessionStorage 5 2 8 10.50 4
Share Button