localStorage in JavaScript | localstorage clear item
Editor’snote:Thispostwasupdatedon29December2020.Inthistutorial,we’llshowyouhowtousethelocalStoragemechanismandWindow.localStoragepropertyandreviewthebasicsofwebstorageinJavaScript.We’llcoverthefollowingindetail:WhatistheWebStorageAPI?TheWebStorageAPI[1]isasetofmechanismsthatenablebrowserstostorekey-valuepairs.Itisdesignedtobemuchmoreintuitivethanusingcookies.Thekey-valuepairsrepresentstorageobjects,whicharesimilartoobjectsexcepttheyremainintactduringpageloads,andarealwaysstrings.Youcanaccess...
Editor’s note: This post was updated on 29 December 2020.
In this tutorial, we’ll show you how to use the localStorage mechanism and Window.localStorage property and review the basics of web storage in JavaScript.
We’ll cover the following in detail:
What is the Web Storage API?The Web Storage API[1] is a set of mechanisms that enable browsers to store key-value pairs. It is designed to be much more intuitive than using cookies.
The key-value pairs represent storage objects, which are similar to objects except they remain intact during page loads, and are always strings. You can access these values like an object or using the getItem() method (more on that later).
What is the difference between sessionStorage and localStorage?The Web Storage API consists of two mechanisms: sessionStorage and localStorage. Both sessionStorage and localStorage maintain a separate storage area for each available origin for the duration of the page session.
Th...