Local Storage Set Item
Syntax:
localStorage.setItem(key,value);
localStorage.getItem(key);
Example:
localStorage.setItem("name","Muthu");
if(localStorage){ //it checks browser support local storage or not
let Name=localStorage.getItem("name");
if(Name!=null){ // it checks values here or not to the variable
//do some stuff here...
}
}
also you can use
localStorage.setItem("name", JSON.stringify("Muthu"));
Session Storage Set Item
Syntax:
sessionStorage.setItem(key,value);
sessionStorage.getItem(key);
Example:
sessionStorage.setItem("name","Muthu");
if(sessionStorage){ //it checks browser support session storage/not
let Name=sessionStorage.getItem("name");
if(Name!=null){ // it checks values here or not to the variable
//do some stuff here...
}
}
also you can use
sessionStorage.setItem("name", JSON.stringify("Muthu"));
Store and Retrieve data easily