P
prepair.app
Start interview →
EnglishУкраїнськаРусский
🟨

JavaScript interview questions

JavaScript interviews concentrate on a small number of things the language does differently from everything else: closures, `this`, prototypes and the event loop. Get those right and most other questions follow. Below are the ones asked most often, each with a model answer.

Junior · no experience / under 1 yearMiddle · 2–4 years of experienceSenior · 5+ years of experience

What they ask about

Types and coercion
Closures and scope
`this` and prototypes
The event loop and async
Promises and async/await
DOM, events and the browser

10 real questions with answers

Every question comes with a model answer you can compare yours against.

1

What data types are there in JavaScript?

Answer

Seven primitives — string, number, boolean, null, undefined, symbol, bigint — and everything else is an object, including arrays and functions. Primitives are copied by value and objects by reference, which is the source of most confusion about why changing one variable changed another. typeof null returns 'object', and that is a bug from 1995 that can never be fixed without breaking the web.

2

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

Answer

var is function-scoped and hoisted as undefined; let and const are block-scoped and sit in the temporal dead zone until the declaration, so touching them early throws instead of silently giving undefined. const prevents rebinding the variable, not mutating the object it points at — const arr = [] still allows arr.push(). Default to const, use let when you must reassign, and never var.

3

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

Answer

=== compares type and value; == coerces first, following rules that produce null == undefined being true while null == 0 is false. Because almost nobody remembers the whole table, the working rule is to always use ===. The one defensible exception is x == null as a shorthand for checking both null and undefined.

4

What is a closure?

Answer

A function together with the scope it was created in, which it keeps access to even after the outer function has returned. It is what makes private state, factory functions, and hooks possible — the inner function holds a live reference, not a copy. The classic interview trap is a var in a loop with setTimeout, where all callbacks share one binding and print the same value; let gives each iteration its own.

5

What is `this` and how is it determined?

Answer

By how the function is called, not where it is defined. Called as a method, this is the object before the dot; called plainly, it is undefined in strict mode; called with new, it is the new object; and call, apply and bind set it explicitly. Arrow functions have no this of their own and take it from the enclosing scope, which is exactly why they fixed the callback problem and exactly why they are wrong as object methods.

6

How does prototypal inheritance work?

Answer

Every object has a hidden link to another object, its prototype. When you read a property that is not there, the engine walks that chain until it finds it or reaches null. class is syntax over this — it creates a constructor function whose prototype object holds the methods, so all instances share one copy of each method rather than each carrying its own.

7

Explain the event loop, macrotasks and microtasks.

Answer

JavaScript runs on one thread with a queue. When the call stack empties, the loop drains the entire microtask queue — promise callbacks, queueMicrotask, MutationObserver — and only then takes one macrotask, such as a setTimeout callback or an event. That is why a .then always runs before a setTimeout(0) scheduled earlier, and why an endless chain of microtasks can starve rendering completely.

8

What is the difference between `Promise.all` and `Promise.allSettled`?

Answer

all rejects as soon as any promise rejects and gives you nothing from the rest; allSettled always resolves with a status per promise. Use all when the whole operation is pointless if one part fails, allSettled when you want to report which parts failed. And note the difference from sequential awaits in a loop — those run one after another, which is usually an accidental performance bug.

9

What is the difference between a shallow and a deep copy?

Answer

A shallow copy — spread or Object.assign — copies the top level, so nested objects are still shared and mutating them affects the original. A deep copy duplicates the whole tree; structuredClone does it natively and handles cycles, Map and Date, while the old JSON.parse(JSON.stringify(x)) trick silently drops functions, undefined and Date types.

10

What is the difference between an arrow function and a regular one?

Answer

An arrow function has no this, no arguments, no prototype, and cannot be called with new. It takes this lexically from where it was defined, which is what makes it right for callbacks and wrong for object methods and prototype methods. It also cannot be used as a constructor or a generator.

🦎

Reading answers is not enough

In a real interview you speak under pressure. Cam asks these same questions, scores every answer, and shows exactly what to fix.

Practice a JavaScript interview →
Free · 3 interviews per month

Worth reading

All articles →

Other specializations

🔍Manual QA🤖QA AutomationJava Backend🐍Python Backend🐘PHP Backend🦫Go Backend🟢Node.js Backend💎Ruby on Rails🔷C++⚛️React Frontend💚Vue Frontend🅰️Angular FrontendNext.js🍏iOS (Swift)🟩Android (Kotlin)⚙️DevOps / SRE🗄️Data Engineer📈Business Analyst🎯Product Manager📋Project Manager🎨UI/UX Designer📣Marketing