JavaScript Interview Questions

Top JavaScript interview questions — from junior to senior level.

Variables & Types

Scope & Closures

Functions

OOP & Prototypes

Async JavaScript

Modern JavaScript

Performance & Memory

Security

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).