20 JavaScript Interview Questions (With Real Answers)
The JavaScript questions that actually come up in junior and mid-level interviews — with honest, thorough answers you can study from.

20 JavaScript Interview Questions (With Real Answers)
These are the questions that come up again and again in junior and mid-level JavaScript interviews.
Fundamentals
1. What is the difference between var, let, and const?
var is function-scoped and hoisted. let and const are block-scoped. const prevents reassignment of the variable binding. In modern JavaScript, let and const are preferred.
2. What is hoisting?
Hoisting is JavaScript's behavior of moving declarations to the top of their scope before execution. Function declarations are fully hoisted. var declarations are hoisted but initialized as undefined. let and const are hoisted but not initialized — accessing them before declaration throws a ReferenceError.
3. What is the difference between == and ===?
== performs type coercion before comparison. === compares both value and type without coercion. Use === unless you have a specific reason to want coercion.
4. What are falsy values in JavaScript?
false, 0, -0, "" (empty string), null, undefined, and NaN. Everything else is truthy — including empty arrays and empty objects.
Functions and Scope
5. What is a closure?
A closure is a function that retains access to its outer lexical scope even after that outer function has returned.
function makeCounter() {
let count = 0;
return () => ++count;
}
const counter = makeCounter();
counter(); // 1
counter(); // 2
6. What does this refer to?
- In a method: the object the method belongs to
- In a standalone function (non-strict): the global object
- In strict mode:
undefined - In an arrow function: inherited from the enclosing lexical scope
Arrays and Objects
7. What is the difference between map, filter, and reduce?
map: transforms each element, returns a new array of the same lengthfilter: keeps elements where the callback returns truereduce: accumulates a single value
8. What is destructuring?
Syntax for extracting values from arrays or objects into variables: const { name, age } = user;
Asynchronous JavaScript
9. What is the event loop?
JavaScript is single-threaded. The event loop manages execution of code, handles events, and executes queued callbacks. Microtasks (promises) run before macro-tasks (setTimeout callbacks).
10. What is a Promise?
A Promise represents a value that will be available asynchronously. States: pending, fulfilled, or rejected.
11. What does async/await do?
async before a function makes it return a Promise. await pauses execution until the awaited Promise resolves. It is syntactic sugar over .then() chains.
12. How do you handle errors in async functions?
Wrap await calls in a try/catch block.
Prototypes and Classes
13. What is the prototype chain?
Every JavaScript object has an internal prototype link to another object. When you access a property, JS looks on the object itself, then walks up the prototype chain.
14. What is the difference between a class and a prototype?
ES6 classes are syntactic sugar over prototype-based inheritance.
Miscellaneous
15. What is the difference between null and undefined?
undefined means a variable was declared but not assigned. null is an intentional assignment indicating "no value".
16. What is a pure function?
A function that always returns the same output for the same input and has no side effects.
17. What is event delegation?
Attaching one listener to a parent instead of each child, using event.target to determine which child was clicked.
18. What is the difference between call, apply, and bind?
call: invokes immediately, arguments passed individuallyapply: invokes immediately, arguments passed as an arraybind: returns a new function withthisbound, doesn't invoke immediately
19. What is optional chaining?
The ?. operator lets you safely access nested properties without throwing if an intermediate value is null or undefined: user?.address?.city.
20. What is the difference between synchronous and asynchronous code?
Synchronous code executes line by line, blocking until each operation completes. Asynchronous code initiates an operation and continues executing other code while waiting for the result.
These 20 questions cover the concepts that come up in the vast majority of JavaScript interviews. The JavaScript Guild certification course covers every one of these concepts in depth.
Share this article
Comments
No comments yet
Sign in to join the conversation.
Sign in to commentBe the first to comment.


