Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

javascript cookies vs session vs local storage

// Cookies
//   Capacity: 4KB
//   Accessible: any window
//   Expiry: manually set
document.cookie = "name=Jet" + new Date(2021, 11, 31).toUTCString(); // expires Dec 31 2021
console.log(document.cookie); // result name=Jet

// Session
//   Capacity: 5MB
//   Accessible: same tab
//   Expiry: on tab close
sessionStorage.setItem("name", "Jet");
console.log(sessionStorage.getItem("name")); // result Jet
sessionStorage.removeItem("name");

// Local Storage
//   Capacity: 10MB
//   Accessible: any window
//   Expiry: never
localStorage.setItem("name", "Jet");
console.log(localStorage.getItem("name")); // result Jet
localStorage.removeItem("name");
Source by # #
 
PREVIOUS NEXT
Tagged: #javascript #cookies #session #local #storage
ADD COMMENT
Topic
Name
8+6 =