Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

localstorage vs sessionstorage

// localstorage vs sessionstorage
// localStorage and sessionStorage are almost identical and have the same API. 
// The difference is that with sessionStorage, the data is persisted only until 
// the window or tab is closed. 
// With localStorage, the data is persisted until the user manually clears the
// browser cache or until your web app clears the data. 

// # localStorage API example: 
// goto devtools & click Application => localStorage to find the key value list
// Add data to localStorage
localStorage.setItem("ls-key", "ls-value"); 

// Get saved data from localStorage 
const value1 = localStorage.getItem("ls-key"); 

// Remove saved data from sessionStorage
localStorage.removeItem('ls-key');

// Remove all saved data from sessionStorage
localStorage.clear();

// # sessionStorage API example:
// goto devtools & click Application => sessionStorage
// Add data to sessionStorage
sessionStorage.setItem("s-key", "s-value"); 

// Get saved data from sessionStorage
const sessionValue = sessionStorage.getItem("s-key");  

// Remove saved data from sessionStorage
sessionStorage.removeItem('s-key');

// Remove all saved data from sessionStorage
sessionStorage.clear();
Comment

PREVIOUS NEXT
Code Example
Javascript :: maths 
Javascript :: get home dir in nodejs 
Javascript :: js localstorage add text 
Javascript :: insertadjacenthtml javascript 
Javascript :: get query string javascript nodejs 
Javascript :: get index of element in array js 
Javascript :: jquery on form submit call function 
Javascript :: how to copy value instead of reference js 
Javascript :: delete element in hash in javascript 
Javascript :: dot env react native 
Javascript :: javascript select text in element 
Javascript :: javascript write to text file 
Javascript :: stop keyframe animation javascript 
Javascript :: hmac_sha256 node 
Javascript :: javascript anagram 
Javascript :: js parse json 
Javascript :: resize function in addEventListener JS 
Javascript :: check if object has method javascript 
Javascript :: toastr 
Javascript :: javascript todataurl 
Javascript :: useeffect only on mount 
Javascript :: javascript string remove substring 
Javascript :: how to add youtube videos to react app 
Javascript :: fetch Response object get content type 
Javascript :: function call ready resize and load 
Javascript :: nextjs global scss variables 
Javascript :: how to make a div appear when clicked on in javascript 
Javascript :: js filter out doubles 
Javascript :: js if dark mode 
Javascript :: generate express js project 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =