Monday 22 July 2019

What is the localStorage in JavaScript?


Window localStorage Property in JavaScript-

The localStorage and sessionStorage properties allow to save key/value pairs in a web browser.
The localStorage object stores data with no expiration date. The data will not be deleted when the browser is closed, and will be available the next day, week, or year.
The localStorage property is read-only.
In  sessionStorage property which stores data for one session (data is lost when the browser tab is closed).
Syntax-
window.localStorage
Syntax for SAVING data to localStorage:
localStorage.setItem("key", "value");
Syntax for READING data from localStorage:
var lastname = localStorage.getItem("key");
Syntax for REMOVING data from localStorage:
localStorage.removeItem("key");

No comments:

Post a Comment