All interview questions Programming · 2026

JavaScript Interview Questions

JavaScript is the most common language topic in frontend and full-stack interviews. These are the questions interviewers actually ask, with concise answers you can speak confidently.

16 questions with concise, interview-ready answers.

1. What is the difference between var, let, and const?

var is function-scoped and hoisted with an initial value of undefined, while let and const are block-scoped and stay in a "temporal dead zone" until declared. let allows reassignment; const does not, though a const object can still have its properties mutated. Prefer const by default and let when you need to reassign.

2. What is the difference between == and ===?

The == operator compares values after coercing both sides to a common type, so 0 == "0" is true. The === operator (strict equality) compares value and type without coercion, so 0 === "0" is false. Prefer === to avoid surprising coercion bugs.

3. What is hoisting?

Hoisting is JavaScript moving declarations to the top of their scope before execution. Function declarations are fully hoisted and callable before their line, while var variables are hoisted but initialized to undefined. let and const are hoisted too but cannot be accessed until their declaration runs, due to the temporal dead zone.

4. What is a closure?

A closure is a function that retains access to variables from its outer (enclosing) scope even after that outer function has returned. It lets you create private state and factory functions. A common example is a counter function that keeps a private count variable alive between calls.

5. How does the "this" keyword work in JavaScript?

The value of "this" depends on how a function is called, not where it is defined. In a regular function it is the calling object (or undefined/global in strict/non-strict mode); with call, apply, or bind you set it explicitly; and as a constructor with new it is the new instance. Arrow functions do not have their own "this" — they inherit it from the enclosing scope.

6. What is prototypal inheritance?

In JavaScript, objects inherit directly from other objects through an internal link called the prototype. When you access a property, the engine walks up the prototype chain until it finds it or reaches null. This is the mechanism behind class inheritance, which is syntactic sugar over prototypes.

7. What is the event loop?

The event loop is what lets single-threaded JavaScript handle asynchronous work without blocking. Synchronous code runs on the call stack first; when it is empty, the loop processes queued callbacks. It drains the entire microtask queue (promises) before taking the next macrotask (timers, I/O, events).

8. What is the difference between microtasks and macrotasks?

Microtasks (promise callbacks, queueMicrotask, MutationObserver) run immediately after the current synchronous code, before any rendering or macrotask. Macrotasks (setTimeout, setInterval, I/O, UI events) run one per event-loop iteration. Because the whole microtask queue is drained between macrotasks, a promise .then() always fires before a setTimeout(0) scheduled at the same time.

9. What is the difference between callbacks, promises, and async/await?

Callbacks are functions passed to run later, but nesting them leads to hard-to-read "callback hell." Promises represent a future value with .then()/.catch() chaining and flatter error handling. async/await is syntactic sugar over promises that lets you write asynchronous code in a synchronous-looking style with try/catch.

10. What is the difference between null and undefined?

undefined means a variable has been declared but not assigned a value, and is the default JavaScript gives. null is an intentional assignment representing "no value." Note that typeof undefined is "undefined" while typeof null is "object" (a long-standing language quirk), and null == undefined is true but null === undefined is false.

11. What is the difference between map, filter, and reduce?

map transforms each element and returns a new array of the same length. filter returns a new array containing only the elements that pass a test. reduce boils the array down to a single accumulated value (a sum, object, or anything else). All three are non-mutating and return new values rather than changing the original array.

12. What is the difference between debounce and throttle?

Debounce delays running a function until a pause in events of a given length, so it fires only once after the activity stops — ideal for search-as-you-type. Throttle guarantees the function runs at most once per time interval no matter how many events fire — ideal for scroll or resize handlers. Both limit how often expensive work runs.

13. What is event delegation?

Event delegation attaches a single listener to a parent element instead of many listeners on its children, relying on event bubbling. Inside the handler you inspect event.target to decide what was clicked. It improves performance and automatically handles dynamically added child elements.

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

A shallow copy (spread operator or Object.assign) duplicates only the top level, so nested objects are still shared by reference. A deep copy clones every nested level so the copy is fully independent. You can deep copy with structuredClone() or, for simple JSON-safe data, JSON.parse(JSON.stringify(obj)).

15. What are the spread and rest operators?

Both use the ... syntax but in opposite directions. Spread expands an iterable into individual elements — copying or merging arrays and objects, or passing array items as function arguments. Rest collects multiple elements into a single array — gathering remaining function parameters or destructured items.

16. What are some key ES6 features?

ES6 (ES2015) introduced let and const, arrow functions, template literals, destructuring, default and rest/spread parameters, classes, modules (import/export), promises, and the Map and Set collections. These features made JavaScript more expressive and are now standard in modern codebases.

Get these answered live in your real interview

NostrobeAI is a real-time AI interview copilot — it hears the question and drafts a strong answer on your screen, invisible on Zoom, Meet, and Teams. One-time pricing, no subscription.

Try NostrobeAI free