JavaScript Interview Questions & Answers
Prepare for JavaScript technical interviews with 100 curated questions and answers — from fundamentals to Tech Lead. Runtime, async, browser APIs, and production patterns. Each question includes a short interview answer, detailed explanation, examples, tips, and common mistakes.
JavaScript interview topics
Jump into a category — each bank is independent and interview-focused.
Execution Context
6 JavaScript questions
Scope
6 JavaScript questions
Hoisting
5 JavaScript questions
Closures
7 JavaScript questions
this
6 JavaScript questions
Prototype
5 JavaScript questions
OOP
5 JavaScript questions
Functional Programming
5 JavaScript questions
Async JavaScript
7 JavaScript questions
Event Loop
7 JavaScript questions
Promises
7 JavaScript questions
Memory Management
5 JavaScript questions
DOM
6 JavaScript questions
Browser APIs
5 JavaScript questions
Performance
6 JavaScript questions
Modules
5 JavaScript questions
Error Handling
7 JavaScript questions
All JavaScript interview questions
Execution Context interview questions
View categoryWhat is an execution context in JavaScript, and what are its main components?
freshWhat happens during the creation phase vs the execution phase of an execution context?
juniorHow does the call stack relate to execution contexts, and what happens on a stack overflow?
juniorExplain the difference between Lexical Environment and Variable Environment in an execution context.
midHow do `eval` and `with` affect execution contexts and scope, and why are they discouraged?
seniorYou are designing a plugin system where third-party scripts run in the same page. How would you reason about execution contexts, isolation, and `this`/`globalThis` risk?
leadScope interview questions
View categoryWhat are global, function, and block scope in JavaScript?
freshHow does the scope chain work when resolving a variable?
juniorCompare `var`, `let`, and `const` in terms of scope, redeclaration, and reassignment.
juniorWhat is the Temporal Dead Zone (TDZ), and how does it show up in interviews?
midHow does module scope differ from classic script global scope?
midExplain illegal shadowing and how `catch` clause bindings interact with block scope.
seniorHoisting interview questions
View categoryWhat is hoisting in JavaScript?
freshHow does hoisting differ between function declarations and function expressions?
juniorWhat is logged and why? ```js console.log(a); console.log(b); var a = 1; let b = 2; ```
midAre ES6 classes hoisted? Can you use a class before its declaration?
midIn non-strict sloppy mode, what happens if two function declarations share the same name in one scope? How should a team prevent related bugs?
seniorClosures interview questions
View categoryWhat is a closure in JavaScript?
freshHow can closures create private state, and when is that useful?
juniorWhy does this print `3 3 3` instead of `0 1 2`, and how do you fix it? ```js for (var i = 0; i < 3; i++) { setTimeout(() => console.log(i), 0); } ```
juniorHow can closures cause memory retention problems?
midImplement a simple `partial` or `multiplyBy` using closures. What interview signal does this show?
midWhat is a stale closure, and how would you diagnose it in an async UI callback?
seniorWhen designing a library API, when would you prefer closure-based factories over class instances with prototype methods?
leadthis interview questions
View categoryHow is the value of `this` determined in JavaScript?
freshWhat are the differences between `call`, `apply`, and `bind`?
juniorWhen should you use an arrow function vs a regular method regarding `this`?
midWhat is logged in strict mode? ```js const obj = { x: 10, getX() { return this.x; }, }; const g = obj.getX; console.log(obj.getX()); console.log(g()); ```
midCompare `this` binding for class prototype methods vs arrow class fields used as callbacks.
seniorYou wrap third-party methods with a Proxy or logging decorator. What `this`-related pitfalls should you design for?
seniorPrototype interview questions
View categoryWhat is the prototype chain, and how does property lookup work?
juniorWhat is the difference between `Fn.prototype` and `obj.__proto__` / `[[Prototype]]`?
juniorWhat does the `new` operator do step by step?
midWhat is prototype pollution, and how do you mitigate it in application code?
seniorAs a tech lead, when (if ever) would you allow mutating built-in prototypes, and what policy would you set?
leadOOP interview questions
View categoryHow does object-oriented programming work in JavaScript compared to classical OOP languages?
freshExplain `extends` and `super` in JavaScript classes. What must a derived constructor do before using `this`?
juniorWhen would you choose composition over inheritance in a JavaScript codebase?
midCompare ES private class fields (`#`) with WeakMap-based privacy patterns.
seniorYou are leading a redesign of a large JS domain layer that mixed anemic data objects with scattered business rules. How would you structure OOP (or FP) boundaries?
leadFunctional Programming interview questions
View categoryWhat are pure functions and immutability, and why do they matter in JavaScript apps?
freshExplain `map`, `filter`, and `reduce` and when a simple `for` loop is better.
juniorWhat is a higher-order function? Write a simple `withRetry` example.
midCompare currying and partial application in JavaScript. When is each useful?
seniorHow far should a team push functional programming style in a large JavaScript/TypeScript product?
seniorAsync JavaScript interview questions
View categoryWhat is the difference between synchronous and asynchronous code in JavaScript?
freshWhat is callback hell, and how did Promises/async-await address it?
juniorHow does `async/await` work under the hood?
juniorHow do you run async operations in parallel vs sequentially with async/await? What are the trade-offs?
midHow do you cancel in-flight async work in the browser, and what cannot be cancelled?
midDescribe a race condition in async UI data loading and how you would fix it.
seniorDesign resilience for a JS client that depends on flaky upstream APIs (timeouts, retries, backoff, idempotency).
leadEvent Loop interview questions
View categoryWhat is the JavaScript event loop?
freshWhat is the difference between microtasks and macrotasks?
juniorPredict the output order: ```js console.log('A'); setTimeout(() => console.log('B'), 0); Promise.resolve().then(() => { console.log('C'); setTimeout(() => console.log('D'), 0); }); console.log('E'); ```
midHow does browser rendering relate to the event loop?
midHow can promise microtasks starve the event loop, and how do you fix it?
seniorHow does Node.js's event loop model differ from the browser's?
seniorAs a lead, how would you set a scheduling strategy for expensive client-side work (hydration, search indexing, analytics) without harming INP?
leadPromises interview questions
View categoryWhat is a Promise in JavaScript?
freshHow does promise chaining work, and what happens if a `.then` handler returns a value vs a promise?
juniorHow should errors be handled with Promises vs async/await?
juniorCompare `Promise.all`, `Promise.allSettled`, `Promise.race`, and `Promise.any`.
midWhat is a thenable, and how would you safely promisify a callback API?
seniorImplement or design a promise pool that runs at most N async tasks at a time.
seniorYou lead multiple teams shipping JS SDKs. What standards would you set for Promise-based APIs?
leadMemory Management interview questions
View categoryHow does memory allocation and garbage collection work at a high level in JavaScript?
juniorWhat are common memory leak patterns in browser JavaScript?
midWhen would you use WeakMap, WeakSet, and WeakRef?
midHow do you diagnose a memory leak using browser DevTools?
seniorHow would you set and enforce a client-side memory budget for a complex SPA?
leadDOM interview questions
View categoryWhat is the DOM, and how does JavaScript interact with it?
freshExplain capturing, targeting, and bubbling in DOM event propagation.
juniorWhat is event delegation and when should you use it?
juniorWhat is the difference between reflow (layout) and repaint, and how can JS trigger them inefficiently?
midWhen would you manipulate the DOM directly vs using a virtual DOM / declarative UI framework?
seniorHow should dynamic DOM updates be designed for accessibility (focus, live regions, semantics)?
seniorBrowser APIs interview questions
View categoryCompare the Fetch API with XMLHttpRequest. When might XHR still appear?
freshCompare localStorage, sessionStorage, and IndexedDB for client-side persistence.
juniorWhat problem does Intersection Observer solve, and how would you use it?
midWhen should you use Web Workers, and what are their limitations?
seniorHow would you choose a service worker caching strategy for an authenticated SPA?
leadPerformance interview questions
View categoryWhat is the difference between debounce and throttle?
freshWhat is the critical rendering path, and how can JavaScript affect it?
juniorHow does code splitting and dynamic `import()` improve performance?
midWhat are long tasks, and how do they relate to INP (Interaction to Next Paint)?
seniorWhen is memoization a good performance strategy in JS, and when does it hurt?
seniorHow would you build a performance culture for a JS frontend org (budgets, tooling, ownership)?
leadModules interview questions
View categoryWhat are the key differences between ES modules and CommonJS?
freshExplain default vs named exports and re-exports. What pitfalls exist?
juniorHow many times is an ES module evaluated, and how does that affect singletons?
midWhat happens with circular dependencies in ESM, and how do you fix them?
seniorHow would you design package `exports` for a library supporting both ESM and CJS consumers?
seniorError Handling interview questions
View categoryHow do `try`, `catch`, and `finally` work in JavaScript?
freshWhat built-in Error types should you know, and when do you create custom errors?
juniorWhy doesn't a surrounding try/catch always catch errors from async code, and how do you fix that?
juniorHow do you distinguish operational errors from programmer errors in a JS service, and how should each be handled?
midHow do you preserve context when wrapping errors across layers (e.g. UI ← API client ← fetch)?
midWhat global error hooks exist in browsers/Node, and what should they do vs not do?
seniorDesign an error-handling strategy for a multi-team JS platform (shared client SDK, web apps, and Node workers).
senior