Skip to main content
InterviewHubPRO
Section Overview
Q45

Question 45 of 536

Part 1: Core Objects, Prototypes, Functions & Scope (1 - 53)

8%
JavaScript & V8 Internals (536 Qs)•Part 1: Core Objects, Prototypes, Functions & Scope (1 - 53)

What are the differences between cookie, local storage and session storage

junior LevelMost AskedCode ExamplePrototypes

Below are some of the differences between cookie, local storage and session storage,

FeatureCookieLocal storageSession storage
Accessed on client or server sideBoth server-side & client-side. The set-cookie HTTP response header is used by server inorder to send it to user.client-side onlyclient-side only
ExpiryManually configured using Expires optionForever until deleteduntil tab is closed
SSL supportSupportedNot supportedNot supported
Maximum data size4KB5 MB5MB
Accessible fromAny windowAny windowSame tab
Sent with requestsYesNoNo

Practical Code Example

javascript
// Comparison of Client Storage Primitives:
// 1. Cookie (~4KB, sent automatically on every HTTP request header)
document.cookie = 'token=abc; SameSite=Lax';

// 2. LocalStorage (~5-10MB, persists forever, client-side only)
localStorage.setItem('cachedUserData', JSON.stringify({ name: 'Sam' }));

// 3. SessionStorage (~5MB, isolated per tab, destroyed on tab close)
sessionStorage.setItem('tempFilter', 'active');