Home› Interview› Top JavaScript Interview Questions
🎯 Interview Prep

Top JavaScript Interview Questions

JavaScript interview questions test everything from core language fundamentals to framework-specific knowledge. This page covers every JavaScript interview resource on TheCodeForge — from closures and prototypes to React and Node.js.

5 Resources

JavaScript interviews concentrate on a small number of mechanisms that the language's syntax deliberately hides: how the event loop schedules work, how closures capture their environment, how this is determined, and how prototypes resolve properties. Almost every question, including the famously tricky ones, is one of those four.

That is why the output-prediction questions are so popular. Asking what a snippet logs, in order, tests all four at once — and reveals immediately whether someone has a mental model or a set of memorised rules.

The event loop, which explains most output-order questions

The runtime has a call stack, a microtask queue and a macrotask queue. Synchronous code runs to completion on the stack. Then all microtasks — promise callbacks, queueMicrotask — drain, including any queued while draining. Only then does one macrotask run: a setTimeout callback, an I/O event.

That ordering is the entire answer to the classic puzzle, and being able to narrate it beats reciting the output.

javascript
console.log('1');
setTimeout(() => console.log('2'), 0);      // macrotask
Promise.resolve().then(() => console.log('3'));  // microtask
console.log('4');

// 1, 4, 3, 2
// Synchronous first (1, 4); microtasks drain fully (3);
// then one macrotask (2) - setTimeout 0 is not "immediately".

// Closures in loops - the interview classic
for (var i = 0; i < 3; i++) setTimeout(() => console.log(i), 0);   // 3 3 3
for (let i = 0; i < 3; i++) setTimeout(() => console.log(i), 0);   // 0 1 2
// var is function-scoped: one binding shared by all three callbacks.
// let is block-scoped: a fresh binding per iteration.

`this`, in five rules applied in order

Nearly every this question resolves by applying these in precedence order, and saying that you are doing so is itself the answer the interviewer wants.

1. An arrow function has no this; it uses the enclosing lexical scope, and bind cannot change it. 2. Called with new: this is the newly-created object. 3. Called with call, apply or bind: whatever was supplied. 4. Called as a method — obj.fn() — this is obj. 5. Otherwise: undefined in strict mode and modules, the global object outside it.

In practiceThe most common real bug from this: extracting a method loses its receiver. const f = obj.method; f() has no obj, because rule 4 applies at the call site and not at assignment. That is why React class components needed bind in the constructor.

What the rest of the round covers

TopicAsked asHave ready
ClosuresWrite a counter / a memoise function / debounceThat the inner function keeps the variable itself alive, not a copy of its value
PrototypesHow does inheritance work without classes?Property lookup walks the prototype chain; class is syntax over it
== versus ===What does == do?Type coercion with a specific algorithm. Use ===; the one idiomatic exception is x == null to catch both null and undefined
PromisesImplement a retry, or explain all vs allSettled vs raceall rejects on the first failure; allSettled never rejects; race settles on the first to settle either way
ModulesESM versus CommonJSESM imports are static and hoisted, enabling tree shaking; CommonJS require is dynamic and synchronous
Debounce / throttleImplement one from scratchDebounce waits for quiet; throttle allows one call per interval. Know which suits search-as-you-type versus scroll

Frequently Asked Questions

How much TypeScript should I know for a JavaScript role?
Enough to be productive: interfaces versus types, generics, union and intersection types, and the common utility types. Most frontend roles now assume it. You should also be able to say that types are erased at compile time and enforce nothing at runtime — a surprisingly common gap.
Do I need to know how React works internally?
For React roles, the parts with observable consequences: reconciliation and why keys matter, the rules of hooks and why they exist, what a dependency array actually compares, and when a re-render happens. Fiber internals are rarely required; the mental model is.
Is it acceptable to use modern syntax in interviews?
Yes, and preferred — optional chaining, nullish coalescing, destructuring, async/await. Writing callback-style promise chains reads as dated. The one caution is being able to explain what the sugar compiles to if asked.
What is the most common JavaScript interview mistake?
Answering output-prediction questions from memory instead of reasoning. Interviewers vary the snippet slightly and memorised answers fall apart. Narrate the event loop or the this rules as you go — the reasoning is what is being assessed.
Should I prepare Node.js as well?
For full-stack and backend roles, yes: the event loop's phases, streams, why require is synchronous, clustering versus worker threads, and how to handle backpressure. For pure frontend roles, a working familiarity with the tooling is usually enough.

Core JavaScript Interview Questions

Browse all Interview resources

74 interview topics across coding patterns, HR questions, aptitude and more.

View All Interview Topics →