What is the difference between localStorage, sessionStorage and cookies?
| Point | localStorage | sessionStorage | Cookies |
|---|---|---|---|
| Lifetime | Until deleted | Until the tab closes | Until the expiry date |
| Size | About 5 MB | About 5 MB | About 4 KB |
| Sent to server | No | No | Yes, 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. |