Interview Prep10 min read

Top 25 JavaScript Interview Questions with Answers (2026)

JavaScript interviews rarely test syntax - they probe the parts that surprise people: how scope and closures work, why the event loop matters, and how asynchronous code actually runs. Get these and frontend interviews stop being scary. Here they are, answered.

A laptop code editor with angle brackets and curly braces representing JavaScript frontend development

Scope, closures & this

What is a closure, and where would you use one?

A closure is a function that remembers variables from the scope where it was defined, even after that scope has returned. It's used for private state - a counter that keeps its own count, or a module that hides its internals.

var vs let vs const, and what is hoisting?

var is function-scoped and hoisted with an initial value of undefined. let and const are block-scoped and sit in a 'temporal dead zone' until declared, so accessing them early throws. const can't be reassigned (though objects it holds can still mutate).

How is 'this' determined?

By how a function is called: as a plain function (global/undefined in strict mode), as a method (the object before the dot), with new (the new instance), or via call/apply/bind. Arrow functions have no own 'this' - they inherit it from the enclosing scope.

The async model

Explain the event loop and what setTimeout(fn, 0) does.

JavaScript runs on a single thread. Synchronous code runs on the call stack; queued callbacks run only when the stack is empty. So setTimeout(fn, 0) doesn't run immediately - it runs after the current synchronous code finishes.

Callbacks vs promises vs async/await?

Promises flatten nested callbacks into chainable .then/.catch. async/await is syntactic sugar over promises that reads like synchronous code. Handle errors with .catch for promises and try/catch for async/await.

Microtasks vs macrotasks?

Promise callbacks are microtasks; timers and I/O callbacks are macrotasks. After each tick, the engine drains all microtasks before the next macrotask - which is why a resolved promise runs before a setTimeout(fn, 0).

Types, equality & ES6+

== vs ===?

=== compares value and type with no coercion; == coerces types before comparing, which causes surprises (e.g. 0 == '' is true). Prefer === unless you deliberately want coercion.

Explain destructuring, spread/rest and default parameters.

Destructuring unpacks values from arrays/objects into variables. Spread (...) copies or merges arrays/objects; rest (...) gathers remaining items into one. Default parameters give a fallback when an argument is undefined.

map vs filter vs reduce?

map transforms each element into a new array of the same length; filter keeps elements that pass a test; reduce folds the array into a single value (sum, object, etc.). Be ready to chain them.

The bottom line

Now go test yourself

JavaScript interviews are won on the fundamentals that trip people up: closures, hoisting, this-binding, and above all the event loop and async model. Frameworks come and go, but an interviewer who sees you truly understand how JavaScript runs will trust you with any of them.

Reading about the event loop and testing your grasp of it are very different things. Start a JavaScript quiz, work through the async and closure questions, and let the explanations turn 'I think I get it' into 'I know it'.

FAQs

Frequently asked questions

What JavaScript topics are asked most in interviews?

Closures and scope, hoisting, the event loop and async/await, this-binding, and ES6+ features like destructuring and array methods.

Do I need to know class components for a frontend interview?

Modern interviews focus on function components and hooks, but knowing the fundamentals of JavaScript - closures, async, this - matters more than any framework detail.

How can I practice JavaScript interview questions quickly?

Take timed MCQ rounds on closures, the event loop and async behaviour, and read the explanation for each answer to lock in the tricky parts.

What is a closure in JavaScript, in simple terms?

A closure is a function that remembers the variables from the scope where it was created, even after that scope has finished running. It's used for private state, like a counter that keeps its own value between calls.

Why does setTimeout(fn, 0) not run immediately?

Because JavaScript is single-threaded. The callback is queued and only runs once the current synchronous code finishes and the call stack is empty - so it's deferred to the next opportunity, not run instantly.

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

=== compares value and type without coercion; == coerces types first, which leads to surprises like 0 == '' being true. Prefer === unless you deliberately want coercion.

What is the difference between var, let and const?

var is function-scoped and hoisted as undefined; let and const are block-scoped and stay in a 'temporal dead zone' until declared. const can't be reassigned, though objects it holds can still be mutated.

What are microtasks and macrotasks?

Promise callbacks are microtasks; timers and I/O callbacks are macrotasks. After each tick the engine drains all microtasks before the next macrotask, which is why a resolved promise runs before a setTimeout.

Is JavaScript enough for a frontend interview, or do I need React too?

Strong JavaScript fundamentals are the foundation, but most frontend roles also test React (or another framework). Pair this with React interview practice for full coverage.

Related quizzes

Put it into practice

Keep reading

Related articles

Browse all articles →

Test yourself in two minutes

Six adaptive questions, every answer explained by an AI tutor. Free.

▶ Start an AI quiz