What is the difference between localStorage, sessionStorage and cookies?

PointlocalStoragesessionStorageCookies
LifetimeUntil deletedUntil the tab closesUntil the expiry date
SizeAbout 5 MBAbout 5 MBAbout 4 KB
Sent to serverNoNoYes, with every request
localStorage.setItem("theme", "dark");
console.log(localStorage.getItem("theme"));

Output:

Tutorials Class - Output Window

dark

Do not store passwords in any of them. See JavaScript Local Storage.


Learn more about the similar topics:
Tutorials
No Content Found.
Exercises & Assignments
No Content Found.
Interview Questions & Answers
No Content Found.