100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
JavaScript

Common JavaScript Interview Questions

A curated set of frequently asked JavaScript interview questions covering fundamentals, closures, the event loop, and ES6+ features.

Error Handling & Interview PrepIntermediate16 min readJul 8, 2026
Analogies

1. Overview

This topic collects the JavaScript questions that show up most often in technical interviews, organized as a quick-reference FAQ. Each question is paired with a concise, accurate answer you can use to check your own understanding or rehearse out loud. Read through them once for comprehension, then use the Quick Reference section to drill the one-liners right before an interview.

🏏

Cricket analogy: Like a batsman revising a coaching manual of common dismissal scenarios in the nets before facing a fast bowler, this topic collects frequent interview questions with concise answers to drill right before the real match.

2. Frequently Asked Questions

What is the difference between var, let, and const?

var is function-scoped (or globally scoped) and is hoisted with an initial value of undefined, allowing it to be referenced (but not meaningfully used) before its declaration line. let and const are block-scoped and are hoisted into a 'temporal dead zone' — they exist in scope but throw a ReferenceError if accessed before their declaration. const additionally prevents reassignment of the binding (though objects/arrays assigned to a const can still be mutated internally).

🏏

Cricket analogy: var is like a fielder placed on the pitch before the toss who can be waved at (undefined) but not bowled to, while let/const are a substitute who legally cannot step on the field (temporal dead zone) until officially named, or it's a foul.

What is a closure in JavaScript?

A closure is a function that retains access to variables from its enclosing lexical scope even after that outer function has returned. Closures are how JavaScript implements private state and factory functions — e.g. a makeCounter() function that returns an increment function which still remembers its own count variable.

🏏

Cricket analogy: A closure is like Virat Kohli's throwing arm still 'remembering' the exact release angle drilled in the nets years ago even after that practice session ended, letting a private counter like makeCounter's count persist.

Explain hoisting in JavaScript.

Hoisting is the JavaScript engine's behavior of processing variable and function declarations during the compile phase, before code executes line by line. Function declarations are hoisted completely (usable before their textual position). var declarations are hoisted with value undefined. let/const declarations are hoisted but remain in the temporal dead zone until their line executes, so accessing them earlier throws a ReferenceError.

🏏

Cricket analogy: Like the toss result being announced fully before play (function fully hoisted), while a substitute's placeholder is visible but undefined, and a suspended player is legally invisible (TDZ) until reinstated.

What is the event loop and how does it work?

The event loop is the mechanism that lets single-threaded JavaScript handle asynchronous work. Synchronous code runs first on the call stack. When it's empty, the event loop drains the microtask queue completely (Promise callbacks, queueMicrotask) before taking a single task from the macrotask queue (setTimeout callbacks, I/O, UI events), then repeats. This is why Promise.resolve().then(...) always runs before a setTimeout(..., 0) callback.

🏏

Cricket analogy: Like an umpire finishing every on-field decision (call stack) before draining the entire third-umpire review queue (microtasks), then processing only one scheduled drinks-break request (macrotask) before repeating.

What does the following code output, and why?

javascript console.log('A'); setTimeout(() => console.log('B'), 0); Promise.resolve().then(() => console.log('C')); console.log('D'); Output: A, D, C, B. Synchronous statements (A, D) run immediately on the call stack. The Promise callback is queued as a microtask and the setTimeout callback as a macrotask; the event loop drains all microtasks (C) before processing the next macrotask (B`), regardless of the 0ms delay.

🏏

Cricket analogy: Like an umpire announcing 'over' and 'drinks' instantly (A, D), then resolving every pending DRS review (C) before finally calling the scheduled strategic timeout (B), regardless of when it was requested.

What does the 'this' keyword refer to in different contexts?

this is determined by how a function is called, not where it's defined (except for arrow functions). As a plain function call, this is undefined in strict mode (or the global object otherwise). As a method call (obj.method()), this is the object before the dot. With new, this is the newly created instance. With call/apply/bind, this is explicitly set. Arrow functions have no own this — they lexically inherit it from their enclosing scope.

🏏

Cricket analogy: Like a bowler's role changing based on who calls the over — the captain's instruction (method call) sets the line, while a spectator shouting from the stands (plain call) has no binding authority at all.

What is the difference between == and ===?

=== (strict equality) compares both value and type with no conversion, so 1 === '1' is false. == (loose equality) performs type coercion before comparing, so 1 == '1' is true. Best practice is to default to === and only use == when coercion is explicitly desired (e.g. value == null to check for both null and undefined).

🏏

Cricket analogy: Like comparing a batter's exact jersey number to a scoreboard digit with no rounding (===, strict), versus a loose commentator's guess that shirt '10' equals score '10' after casual conversion (==).

What are prototypes and how does prototypal inheritance work?

Every JavaScript object has an internal link ([[Prototype]], accessible via Object.getPrototypeOf or the deprecated __proto__) to another object it can delegate property lookups to. If a property isn't found on the object itself, the engine walks up this prototype chain. class syntax and constructor functions with .prototype are just ergonomic ways to set up this chain — under the hood, class B extends A makes B.prototype's prototype equal to A.prototype.

🏏

Cricket analogy: Like a young player inheriting technique from their state academy coach, who inherited it from a national coach — if a shot isn't in the player's own game, they fall back on what the academy taught them.

What is the difference between null and undefined?

undefined means a variable has been declared but not assigned a value, or a property/argument simply doesn't exist. null is an explicit assignment representing 'intentionally no value.' They are loosely equal (null == undefined is true) but strictly unequal (null === undefined is false), and typeof null famously returns 'object' — a long-standing quirk of the language.

🏏

Cricket analogy: Like a scorecard slot for 'Man of the Match' left blank because it hasn't been decided yet (undefined), versus explicitly marking a rained-off match's result as 'No Result' (null) — absence versus a deliberate statement.

What are Promises and how do they differ from plain callbacks?

A Promise represents the eventual result (or failure) of an asynchronous operation as a first-class object with states pending, fulfilled, or rejected. Unlike raw callbacks, Promises can be chained with .then(), composed with Promise.all/Promise.race, and avoid 'callback hell' (deep nesting). They also standardize error propagation — a rejection skips to the next .catch() automatically instead of requiring manual error-first checks at every step.

🏏

Cricket analogy: Like a pending DRS review that will eventually resolve as 'out' or 'not out' (pending/fulfilled/rejected), letting the next decision chain automatically instead of the umpire manually re-checking after every single appeal.

What are arrow functions and how do they differ from regular functions?

Arrow functions ((a, b) => a + b) have no own this, arguments, or super — they capture these lexically from the enclosing scope, making them ideal for callbacks that need to preserve the outer this. They also cannot be used as constructors (new throws), have no prototype property, and cannot be used as generator functions.

🏏

Cricket analogy: Like a stand-in fielder who has no fielding position of their own and simply mirrors whatever position the captain assigned to the spot they're covering, never claiming an independent role.

3. Quick Reference

  • var = function scope, hoisted as undefined; let/const = block scope, temporal dead zone.
  • Closures = a function + the lexical scope it remembers, even after the outer function returns.
  • Event loop order: synchronous code → all microtasks (Promises) → one macrotask (setTimeout) → repeat.
  • === never coerces types; == does.
  • Arrow functions inherit this lexically and cannot be used with new.
  • typeof null === 'object' is a historical bug in the language, not a design choice.

4. Key Takeaways

  • Interviewers test both conceptual understanding (scoping, closures, prototypes) and code-tracing ability (event loop order, this binding).
  • Always be ready to explain the 'why' behind an answer, not just recite a definition.
  • Practice tracing asynchronous code by mentally separating the call stack, microtask queue, and macrotask queue.
  • Know the practical difference between ==/=== and null/undefined — these are near-universal warm-up questions.
  • Be able to explain this binding rules for plain calls, method calls, new, call/apply/bind, and arrow functions.

Practice what you learned

Was this page helpful?

Topics covered

#JavaScript#JavaScriptProgrammingStudyNotes#Programming#CommonJavaScriptInterviewQuestions#Common#Interview#Questions#Frequently#StudyNotes#SkillVeris