JavaScript Interview Questions
Top JavaScript interview questions — from junior to senior level.
Variables & Types
- What's the difference between
var,let, andconst? - What are the primitive types in JavaScript?
- What is type coercion? Give examples.
- What are falsy values?
- What is
NaN? How do you check for it?
Scope & Closures
- What is scope? Types of scope in JS?
- What is hoisting?
- What is a closure? Give a practical example.
- What is the Temporal Dead Zone?
Functions
- Difference between function declaration and expression?
- What are higher-order functions?
- What is currying?
- What is an IIFE?
- What is the difference between
call,apply, andbind?
OOP & Prototypes
- How does prototypal inheritance work?
- What is
this? How does it change context? - Difference between
classand prototype-based inheritance?
Async JavaScript
- How does the event loop work?
- What are microtasks vs macrotasks?
- What is a Promise? States?
- Difference between
async/awaitand Promises? - What is
Promise.allvsPromise.allSettled? - What are generators?
Modern JavaScript
- What is destructuring?
- Difference between rest and spread?
- What are WeakMap and WeakSet?
- What is the difference between
==and===? - How does
Symbolwork?
Performance & Memory
- How does garbage collection work in JavaScript?
- What is the V8 engine?
- What is a memory leak? How to prevent it?
Security
- What is XSS? How to prevent it?
- What is CORS? How does it work?
- What is CSRF?
Sample Answers
What is a closure?
// A closure is a function that remembers variables from
// its outer scope even after the outer function has returned.
function makeAdder(x) {
return function(y) {
return x + y // 'x' is closed over
}
}
const add5 = makeAdder(5)
add5(3) // 8
add5(10) // 15
What is the event loop?
JavaScript is single-threaded. The event loop allows non-blocking operations by offloading work to Web APIs, then queuing callbacks. Microtasks (Promises) are processed before macrotasks (setTimeout).