Student Senior BlogBlogs

50 JavaScript Interview Questions and Answers for Developers in 2026

Sahil Verma
October 1, 2026
15 min read
Banner for 50 JavaScript Interview Questions and Answers for Developers in 2026

AI Summary

Get a quick overview of the key points

Tap Generate Magic to let AI read for you.

Preparing for a JavaScript, React, or Node.js interview? Here are 50 commonly asked questions explained in simple English, with short examples and useful resources.

JavaScript interviews are not only about writing code. Interviewers often want to know whether you understand how JavaScript actually works.

Questions about var, let, closures, promises, async/await, the event loop, modules, and objects are common because they show how well you understand the language.

So, instead of memorizing complicated definitions, let's understand these questions in the simplest way possible.


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

This is one of the first JavaScript questions many interviewers ask.

The main difference is scope and reassignment.

js
1var name = "Sahil"; 2let age = 21; 3const country = "India";
  • var is function-scoped.
  • let is block-scoped.
  • const is also block-scoped.
  • let can be reassigned.
  • const cannot be reassigned.
js
1let age = 21; 2age = 22; // ✅ 3 4const country = "India"; 5country = "USA"; // ❌

Simple rule: Prefer const by default. Use let when the value needs to change. Avoid var in modern JavaScript.

📚 MDN — Variables and declarations


2. What is hoisting?

Hoisting means JavaScript processes certain declarations before running the code.

For example:

js
1console.log(name); 2 3var name = "Sahil";

This doesn't immediately throw an error because var is hoisted and initialized with undefined.

Conceptually, it behaves somewhat like:

js
1var name; 2 3console.log(name); 4 5name = "Sahil";

However, let and const behave differently because of the Temporal Dead Zone (TDZ).

📚 MDN — Hoisting


3. What is the Temporal Dead Zone?

The Temporal Dead Zone is the time between entering a block and reaching the declaration of a let or const variable.

js
1console.log(name); // ❌ ReferenceError 2 3let name = "Sahil";

The variable exists in the scope, but you cannot access it before its declaration.

Easy way to remember: let and const are hoisted, but they cannot be used before their declaration.

📚 MDN — let


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

== compares values after performing type conversion.

=== compares both value and type.

js
15 == "5" // true 25 === "5" // false

In modern JavaScript, === is generally preferred because it avoids unexpected type conversion.

📚 MDN — Equality comparisons


5. What are primitive data types in JavaScript?

JavaScript has seven primitive types:

  • String
  • Number
  • BigInt
  • Boolean
  • Undefined
  • Symbol
  • Null

Example:

js
1let name = "Sahil"; // String 2let age = 21; // Number 3let active = true; // Boolean 4let value = undefined; // Undefined 5let data = null; // Null

Objects, arrays, and functions are not primitive values.

📚 MDN — Data types


Objects and Copying

6. What is the difference between shallow copy and deep copy?

This is a very common interview question.

Suppose we have:

js
1const user = { 2 name: "Sahil", 3 address: { 4 city: "Lucknow" 5 } 6};

A shallow copy copies only the first level.

js
1const copy = { ...user };

But address is still shared between both objects.

A deep copy creates independent nested objects too.

js
1const copy = structuredClone(user);

Now changing:

js
1copy.address.city = "Delhi";

doesn't change the original object.

Remember:

Shallow copy → nested references are shared Deep copy → nested data is copied too

📚 MDN — structuredClone


7. How can you create a shallow copy of an object?

Two common ways are:

js
1const copy = { ...user };

or:

js
1const copy = Object.assign({}, user);

Both create a shallow copy.

📚 MDN — Spread syntax


8. What is destructuring?

Destructuring lets you take values from an object or array and store them in variables.

Without destructuring:

js
1const user = { 2 name: "Sahil", 3 age: 21 4}; 5 6const name = user.name; 7const age = user.age;

With destructuring:

js
1const { name, age } = user;

It makes code shorter and easier to read.

📚 MDN — Destructuring


9. What is the difference between map(), filter(), and reduce()?

These three array methods are extremely common in interviews.

map()

Creates a new array by changing every element.

js
1const numbers = [1, 2, 3]; 2 3const result = numbers.map(n => n * 2); 4 5console.log(result); 6// [2, 4, 6]

filter()

Keeps elements that satisfy a condition.

js
1const result = numbers.filter(n => n > 1); 2 3// [2, 3]

reduce()

Combines an array into a single value.

js
1const result = numbers.reduce((sum, n) => sum + n, 0); 2 3// 6

Easy way to remember:

map → transform filter → select reduce → combine

📚 MDN — Array


Functions and Closures

10. What is a closure?

A closure happens when a function remembers variables from its outer scope even after the outer function has finished executing.

js
1function counter() { 2 let count = 0; 3 4 return function () { 5 count++; 6 return count; 7 }; 8} 9 10const increment = counter(); 11 12console.log(increment()); // 1 13console.log(increment()); // 2

The inner function still remembers count.

Closures are commonly used for:

  • Data privacy
  • Counters
  • Callbacks
  • Function factories
  • React hooks and other patterns

📚 MDN — Closures


11. What is the difference between an arrow function and a normal function?

Arrow functions have a shorter syntax:

js
1const add = (a, b) => a + b;

But the important interview difference is this.

Arrow functions do not create their own this. They use this from their surrounding scope.

Normal functions have their own this depending on how they are called.

📚 MDN — Arrow functions


12. What is this in JavaScript?

this refers to the object associated with the current function call.

For example:

js
1const user = { 2 name: "Sahil", 3 4 sayHello() { 5 console.log(this.name); 6 } 7}; 8 9user.sayHello();

Here, this refers to user.

One important thing to remember is that this depends on how a function is called, not simply where it was created.

📚 MDN — this


Promises and Async JavaScript

13. What is a Promise?

A Promise represents the result of an asynchronous operation.

For example, when you make an API request, you don't immediately know whether it will succeed or fail.

A Promise can be:

  • pending
  • fulfilled
  • rejected
js
1const promise = fetch("/api/users"); 2 3promise 4 .then(response => response.json()) 5 .catch(error => console.log(error));

📚 MDN — Using promises


14. What is async/await?

async/await is a cleaner way to work with Promises.

Instead of:

js
1fetch("/api/users") 2 .then(response => response.json()) 3 .then(data => console.log(data));

You can write:

js
1async function getUsers() { 2 const response = await fetch("/api/users"); 3 const data = await response.json(); 4 5 console.log(data); 6}

It makes asynchronous code easier to read.

📚 MDN — async function


15. Does an async function always return a Promise?

Yes.

js
1async function hello() { 2 return "Hello"; 3}

Even though we return a string, JavaScript automatically wraps it in a Promise.

js
1hello().then(result => { 2 console.log(result); 3});

📚 MDN — async function


16. Does await block JavaScript?

No.

await pauses the current async function, not the entire JavaScript runtime.

This is an important distinction.

js
1async function test() { 2 const data = await fetch("/api"); 3}

Other JavaScript work can continue while the asynchronous operation is waiting.

📚 MDN — await


17. What is Promise.all()?

Promise.all() lets you wait for multiple Promises together.

js
1const [users, posts] = await Promise.all([ 2 fetchUsers(), 3 fetchPosts() 4]);

The operations can run concurrently.

However, if one Promise rejects, Promise.all() rejects.

📚 MDN — Promise.all


18. What is the difference between Promise.all() and Promise.allSettled()?

Promise.all() fails when one Promise fails.

Promise.allSettled() waits for every Promise, regardless of success or failure.

This makes allSettled() useful when you want the result of every operation.

📚 MDN — Promise.allSettled


Event Loop

19. What is the JavaScript Event Loop?

JavaScript executes synchronous code using the call stack.

When asynchronous work is involved, the runtime schedules callbacks and the event loop helps decide when those callbacks can run.

A simplified model is:

Call Stack → Runtime APIs → Queues → Event Loop → Call Stack

This is one of the most important concepts for JavaScript and Node.js interviews.

📚 MDN — JavaScript execution model


20. What is the Call Stack?

The call stack keeps track of functions currently being executed.

js
1function one() { 2 two(); 3} 4 5function two() { 6 console.log("Hello"); 7} 8 9one();

JavaScript pushes functions onto the stack and removes them when they finish.

If the stack becomes too large, you can get:

text
1Maximum call stack size exceeded

📚 MDN — Execution model


21. What is a microtask?

A microtask is a high-priority asynchronous task.

Promise callbacks are a common example:

js
1Promise.resolve().then(() => { 2 console.log("Microtask"); 3});

Microtasks are processed before the next task is taken from the task queue.

📚 MDN — Microtasks


22. What is a macrotask?

The term "macrotask" is commonly used for tasks such as timers and event callbacks.

For example:

js
1setTimeout(() => { 2 console.log("Timer"); 3}, 0);

The callback doesn't run immediately. It gets scheduled as a task.

📚 MDN — Microtask guide


23. Which runs first: Promise or setTimeout?

Consider:

js
1console.log("A"); 2 3setTimeout(() => console.log("B"), 0); 4 5Promise.resolve().then(() => console.log("C")); 6 7console.log("D");

Output:

text
1A 2D 3C 4B

Why?

  1. Synchronous code runs first.
  2. Promise callback goes to the microtask queue.
  3. Timer callback goes to the task queue.
  4. Microtasks are processed before the next task.

This is a very common output-based interview question.


Modules

24. What is the difference between import and require()?

import belongs to the ES Module system.

js
1import express from "express";

require() belongs to CommonJS.

js
1const express = require("express");

Modern Node.js supports both module systems, although their configuration and behavior differ.

📚 Node.js — Modules 📚 Node.js — ECMAScript Modules


25. What is the difference between default and named exports?

Named export:

js
1export const name = "Sahil";

Import:

js
1import { name } from "./user.js";

Default export:

js
1export default function hello() {}

Import:

js
1import hello from "./user.js";

A file can have multiple named exports but only one default export.

📚 MDN — import


More Questions You Should Know

26. What is event bubbling?

When an event happens on a child element, it can move upward through its parent elements.

text
1button 2 ↓ 3div 4 ↓ 5body 6 ↓ 7document

This is called event bubbling.

📚 MDN — Event bubbling


27. What is event delegation?

Instead of adding listeners to every child, you add one listener to the parent.

js
1list.addEventListener("click", event => { 2 if (event.target.matches("button")) { 3 console.log("Button clicked"); 4 } 5});

It is useful when dealing with many or dynamically created elements.


28. What is debouncing?

Debouncing waits until the user stops triggering an event before running a function.

A common example is a search box.

Instead of making an API request for every keystroke:

text
1J 2Ja 3Jav 4Java 5JavaS 6JavaSc...

you wait until the user stops typing.

📚 MDN — Debounce


29. What is throttling?

Throttling limits how frequently a function can execute.

For example, you might limit a scroll handler to run once every 100ms instead of hundreds of times per second.

📚 MDN — Throttle


30. What is optional chaining?

Optional chaining allows you to safely access nested properties.

Instead of:

js
1user && user.address && user.address.city

you can write:

js
1user?.address?.city

If something doesn't exist, JavaScript returns undefined instead of throwing an error.

📚 MDN — Optional chaining


31. What is the nullish coalescing operator?

The ?? operator provides a fallback when a value is null or undefined.

js
1const name = user.name ?? "Guest";

Unlike ||, it doesn't treat values like 0 or false as missing.

📚 MDN — Nullish coalescing


32. What is a callback function?

A callback is simply a function passed to another function.

js
1function greet(name, callback) { 2 console.log("Hello " + name); 3 callback(); 4} 5 6greet("Sahil", () => { 7 console.log("Done"); 8});

Callbacks are heavily used in asynchronous JavaScript.

📚 MDN — Callback function


33. What is a higher-order function?

A higher-order function either:

  • accepts another function as an argument, or
  • returns another function.

For example:

js
1const numbers = [1, 2, 3]; 2 3const result = numbers.map(n => n * 2);

Here, map() is a higher-order function because it accepts a function.


34. What are call(), apply(), and bind()?

All three can control the value of this.

js
1user.sayHello.call(otherUser);

The main difference:

  • call() → arguments separately
  • apply() → arguments as an array
  • bind() → returns a new function

📚 MDN — Function


35. What is a prototype?

Every JavaScript object can have access to another object called its prototype.

JavaScript uses prototypes for inheritance.

js
1const user = { 2 name: "Sahil" 3}; 4 5console.log(user.toString);

You didn't define toString() yourself. It comes through the prototype chain.

📚 MDN — Inheritance and prototype chain


36. What is the prototype chain?

When JavaScript cannot find a property on an object, it looks at its prototype.

It continues looking up the chain until it finds the property or reaches null.

text
1object 2 ↓ 3prototype 4 ↓ 5prototype 6 ↓ 7null

This is called the prototype chain.


37. What is the difference between Map and Object?

Both can store key-value pairs, but they are designed differently.

Map provides useful features such as:

js
1const users = new Map(); 2 3users.set("id", 101); 4users.get("id");

Map supports keys of any type and has methods like set(), get(), and has().

Objects are often better when you're representing structured data.

📚 MDN — Map


38. What is a Set?

A Set stores unique values.

js
1const numbers = new Set([1, 2, 2, 3]); 2 3console.log(numbers); 4// Set {1, 2, 3}

A common use is removing duplicates from an array:

js
1const unique = [...new Set(numbers)];

📚 MDN — Set


39. What is memoization?

Memoization means storing the result of an expensive function so you don't have to calculate it again.

For example, if a function receives the same input multiple times, you can cache the previous result.

It's useful for optimization but should be used when the memory cost is worth the performance benefit.


40. What is currying?

Currying transforms a function with multiple arguments into a series of functions with one argument.

Instead of:

js
1add(2, 3);

you might have:

js
1add(2)(3);

It is a common functional-programming concept.


JavaScript + Browser

41. What is the DOM?

DOM stands for Document Object Model.

The browser converts an HTML document into a tree-like structure that JavaScript can interact with.

js
1document.querySelector("#title");

JavaScript can then read or modify the page through the DOM.

📚 MDN — DOM


42. What is CORS?

CORS stands for Cross-Origin Resource Sharing.

It is a browser security mechanism that controls whether a web page can make requests to another origin.

For example:

text
1Frontend: https://myapp.com 2API: https://api.example.com

The server needs to allow the appropriate cross-origin request.

📚 MDN — CORS


43. What is fetch()?

fetch() is a browser API used to make HTTP requests.

js
1const response = await fetch("/api/users"); 2 3const users = await response.json();

It returns a Promise.

📚 MDN — Fetch API


44. What is AbortController?

AbortController allows you to cancel certain asynchronous operations, including fetch() requests.

js
1const controller = new AbortController(); 2 3fetch("/api/users", { 4 signal: controller.signal 5}); 6 7controller.abort();

This is useful when a request is no longer needed.

📚 MDN — AbortController


Node.js Questions

45. Is Node.js single-threaded?

JavaScript execution in Node.js primarily happens on a single main thread, but Node.js can use additional threads and system facilities for certain operations.

This is why saying simply "Node.js is single-threaded" can be misleading.

📚 Node.js — Don't Block the Event Loop


46. What is the Node.js Event Loop?

The Node.js event loop allows Node.js to handle asynchronous operations without blocking the main JavaScript execution thread.

It is one of the main reasons Node.js works well for I/O-heavy applications.

📚 Node.js — Event Loop


47. What is process.nextTick()?

process.nextTick() schedules a callback to run after the current operation completes, before the event loop continues to later phases.

js
1process.nextTick(() => { 2 console.log("next tick"); 3});

It is specific to Node.js and should be used carefully because excessive use can delay other work.

📚 Node.js — process.nextTick


48. What is CommonJS?

CommonJS is a module system traditionally used by Node.js.

Example:

js
1const express = require("express"); 2 3module.exports = router;

It uses require() and module.exports.

📚 Node.js — CommonJS modules


49. What are ES Modules?

ES Modules, commonly called ESM, are JavaScript's standard module system.

They use:

js
1import express from "express";

and:

js
1export default router;

Modern browsers and Node.js support ES Modules.

📚 Node.js — ECMAScript Modules


50. What is the difference between synchronous and asynchronous JavaScript?

Synchronous code runs one operation at a time and waits for each operation to finish.

js
1const result = calculate(); 2console.log(result);

Asynchronous code allows JavaScript to start an operation and continue doing other work while waiting for the result.

js
1const data = await fetchData();

Understanding asynchronous JavaScript is essential for working with APIs, databases, Node.js, React, and real-world applications.

📚 MDN — Asynchronous JavaScript

#javascript interview questions#js interview questions#javascript interview questions for freshers