JavaScript Internals (521 Qs)•Part 1: Core Objects, Prototypes, Functions & Scope (1 - 53)
Why do you need web storage
Web storage is more secure, and large amounts of data can be stored locally, without affecting website performance. Also, the information is never transferred to the server. Hence this is a more recommended approach than Cookies.
Practical Code Example
javascript
// Why Web Storage: Unlike cookies, Web Storage avoids transmitting data in HTTP headers!
// Saving high-volume UI state without adding 5KB to every API request:
const userDraft = { title: 'Post Draft', content: 'Lorem ipsum...' };
localStorage.setItem('post_draft_autosave', JSON.stringify(userDraft));
const recovered = JSON.parse(localStorage.getItem('post_draft_autosave'));
console.log(recovered.title); // 'Post Draft'