localStorage.setItem('theme', 'dark');
sessionStorage.setItem('draftId', '42');
Topics
37
ArrayBuffer, TypedArrays & Binary Data
Arrays & Array Methods
Async Iterators & Streams
Browser Storage & Web APIs
Classes & Class Syntax
Date, Time & Internationalization (Intl API)
Debugging, Testing & Tooling
Design Patterns in JavaScript
Destructuring, Spread & Rest
DOM & Events
Error Handling
ES Modules
Event Loop & Concurrency
Functional Programming
Iterators & Generators
JSON & Data Serialization
Map, Set, WeakMap & WeakSet
Memory Management & Garbage Collection
Networking: Fetch, XHR, WebSockets & CORS
Numbers, Math & BigInt
Objects, Property Descriptors & Immutability
Optional Chaining & Nullish Coalescing
Package Management, Bundlers & Transpilation (npm, Webpack/Vite, Babel)
Performance Optimization: Debouncing, Throttling & Memoization
Promises & async/await
Prototypes & Inheritance
Proxy & Reflect
Regular Expressions
Scope, Hoisting & Closures
Security: XSS, CSRF & Content Security Policy
Service Workers & Progressive Web Apps
Strings & Template Literals
Symbols & Well-Known Symbols
this & Binding
Types & Coercion
Web Components & Custom Elements
Web Workers & Multithreading
Browser Storage & Web APIs
10 questions found
localStorage persists data with no expiration until explicitly cleared, and is shared across all tabs/windows for the same origin. sessionStorage only lasts for the lifetime of a single tab and is cleared when that tab closes.
Real-world example
localStorage for remembering a user's theme preference; sessionStorage for a temporary multi-step form draft.
JSON & Data Serialization
localStorage's API only accepts and returns strings. To store objects or arrays, serialize them with JSON.stringify() before saving and JSON.parse() them back out after reading.
localStorage.setItem('user', JSON.stringify({ name: 'Sam' }));
const user = JSON.parse(localStorage.getItem('user'));
Real-world example
Caching a user's settings object client-side so the app loads instantly on return visits.
JSON & Data Serialization
The storage event fires on window in OTHER tabs/windows of the same origin whenever localStorage changes — it never fires in the tab that made the change itself. It's useful for keeping multiple open tabs in sync.
window.addEventListener('storage', (e) => {
console.log(e.key, e.oldValue, e.newValue);
});
Real-world example
Logging a user out in every open tab the instant they log out in one tab.
DOM & Events
localStorage is typically capped around 5–10MB per origin and is synchronous, which can block the main thread on large reads/writes. IndexedDB supports much larger amounts of data (often hundreds of MB or more, browser-dependent) and is fully asynchronous.
// localStorage: simple, small, synchronous
localStorage.setItem('flag', 'true');
// IndexedDB: larger, async, more setup
const request = indexedDB.open('MyDB', 1);
Real-world example
Using IndexedDB to cache an offline-capable app's entire product catalog, which wouldn't fit in localStorage.
Memory Management & Garbage Collection
IndexedDB is a low-level, transactional NoSQL database built into the browser. It supports structured objects, indexes for fast querying by property, and versioned schema upgrades — well beyond a flat key-value store like localStorage.
const request = indexedDB.open('AppDB', 1);
request.onupgradeneeded = (e) => {
const db = e.target.result;
db.createObjectStore('notes', { keyPath: 'id' });
};
Real-world example
Building an offline-first note-taking app that needs to query notes by date or tag.
Design Patterns in JavaScript
Cookies are automatically sent with every HTTP request to their domain (adding overhead), have a much smaller size limit (~4KB), and can be marked HttpOnly so JavaScript can't read them at all — useful for session tokens. localStorage never travels with requests and is always JS-accessible.
document.cookie = 'sessionId=abc123; Secure; SameSite=Strict';
localStorage.setItem('sessionId', 'abc123'); // different use case
Real-world example
Storing an auth session token in an HttpOnly cookie to protect it from XSS, versus storing UI preferences in localStorage.
Security: XSS
CSRF & Content Security Policy
The Cache API lets you store Request/Response pairs programmatically, most commonly from within a Service Worker, to serve assets offline or speed up repeat loads. Unlike browser HTTP caching, you fully control what's cached and for how long.
caches.open('v1').then(cache => {
cache.addAll(['/', '/styles.css', '/app.js']);
});
Real-world example
Precaching an app's shell so it still loads (with a fallback UI) when the user is offline.
Service Workers & Progressive Web Apps
navigator.geolocation.getCurrentPosition() asynchronously requests the user's location, always requiring explicit browser permission first. It should only be called after a clear user action, since silent location requests are a major privacy red flag and often blocked or flagged by browsers.
navigator.geolocation.getCurrentPosition(
pos => console.log(pos.coords.latitude, pos.coords.longitude),
err => console.error(err.message)
);
Real-world example
A delivery app asking for location only when the user taps "Use my current location."
Networking: Fetch
XHR
WebSockets & CORS
What does the Intersection Observer API do and why is it preferred over scroll event listeners?
AdvancedIntersectionObserver asynchronously watches when a target element enters or leaves the viewport (or another container), without the performance cost of firing on every scroll event and manually computing element positions.
const observer = new IntersectionObserver((entries) => {
entries.forEach(e => { if (e.isIntersecting) loadImage(e.target); });
});
observer.observe(document.querySelector('img.lazy'));
Real-world example
Implementing lazy-loading images or infinite scroll without janky scroll-handler performance.
Performance Optimization: Debouncing
Throttling & Memoization
Use the StorageManager API's navigator.storage.estimate(), which returns a Promise resolving to an object with usage and quota (both in bytes), covering localStorage, IndexedDB, Cache API, and other origin storage combined.
const { usage, quota } = await navigator.storage.estimate();
console.log(`Using ${usage} of ${quota} bytes`);
Real-world example
Warning users before an offline-capable app runs out of storage space for cached data.
Memory Management & Garbage Collection