Table of Contents

🚀 JavaScript Interview Questions & Answers (2025 Guide)

Picture of Arsalan Khatri

Arsalan Khatri

I’m Arsalan Khatri AI Engineer & WordPress Developer helping businesses and individuals grow online through professional web solutions and IT knowledge sharing by Publish articles.

JavaScript Interview Questions & Answers
Picture of Arsalan Khatri

Arsalan Khatri

AI Engineer & WordPress Developer helping people grow online through web solutions and insightful tech articles.

“JavaScript interviews can be tricky! Sometimes, it’s not about what you know — it’s about how well you explain it. In this guide, you’ll find basic to advanced JavaScript questions (with examples) that interviewers love asking in 2025.”

🚀 Why JavaScript Matters in 2025

JavaScript is not just another programming language — it’s the backbone of modern web development. From simple websites to advanced single-page applications, from mobile apps to server-side programming (Node.js), JavaScript powers it all.

In fact, according to recent reports, over 95% of websites worldwide use JavaScript. It’s also one of the most in-demand skills in tech interviews. Whether you’re a beginner preparing for your first job, or an experienced developer targeting a senior role, JavaScript interview questions are unavoidable.

This blog covers everything you need:
✅ Basic questions to test your fundamentals
✅ Medium-level questions to check your problem-solving
✅ Advanced and tricky ones to challenge your depth of knowledge

👉 So, if you want to crack your next interview and stand out from the crowd, let’s dive into the top JavaScript interview questions of 2025.

JavaScript Interview Questions & Answers 👇

1) 10 Basic Level JavaScript Interview Questions

Q1. What is JavaScript?

Answer

JavaScript is a lightweight, interpreted scripting language used to make web pages interactive and dynamic.

Q2. What is the difference between Java and JavaScript?

Answer

  • Java: Object-oriented, strongly typed, runs on JVM.

  • JavaScript: Scripting language, loosely typed, runs directly in browsers.

Q3. What are the data types in JavaScript?

Answer

  • Primitive types: number, string, boolean, null, undefined, symbol, bigint

  • Reference types: object, array, function

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

Answer

  • var: function-scoped, can be redeclared.

  • let: It is block-scoped, allows reassignment, but doesn’t permit redeclaration within the same scope.

  • const: block-scoped, cannot be reassigned or redeclared.

Q5. What is the “this” keyword in JavaScript?

“this” points to the object running the function, and its value changes depending on how the function is used.

Q6. What are arrays in JavaScript?

Answer

An array is used to hold many values together inside one variable.

let fruits = ["Apple", "Mango", "Banana"];

Q7. What are functions in JavaScript?

Answer

Functions are reusable blocks of code designed to perform a specific task.

function greet() {
return "Hello!";
}

Q8. What is an Object in JavaScript?

Answer

An object is a collection of key-value pairs.

let car = { brand: "Toyota", model: "Corolla", year: 2025 };

Q9. What is DOM in JavaScript?

Answer

DOM (Document Object Model) is a programming interface that represents HTML as a tree structure, allowing JavaScript to manipulate web page content dynamically.

Q10. What are events in JavaScript?

Answer

Events are actions that occur in the browser (e.g., click, keypress, mouseover). JavaScript can handle these events.

document.getElementById("btn").addEventListener("click", () => {
alert("Button clicked!");
});

“Once you’re confident with these, continue to the next level for an even greater challenge.”

2) 10 Medium Level JavaScript Interview Questions

Q11. What is the difference between == and === in JavaScript?

Answer

  • == (Equality Operator): Compares values after type conversion (loose equality).

  • === (Strict Equality Operator): Compares both value and type without conversion.

0 == "0"; // true
0 === "0"; // false

Q12. What is Hoisting in JavaScript?

Answer

Hoisting is JavaScript’s default behavior of moving declarations (variables and functions) to the top of their scope before code execution.

console.log(x); // undefined
var x = 5;

Q13. What are Closures in JavaScript?

Answer

A closure is a function that can use variables from its outer function, even if the outer function has already finished.

function outer() {
let count = 0;
return function() {
count++;
return count;
};
}
let counter = outer();
console.log(counter()); // 1
console.log(counter()); // 2

Q14. What are Arrow Functions in JavaScript?

Answer

Arrow functions provide a simple and shorter way to write functions. They also do not have their own this context, but inherit it from their parent scope.

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

Q15. What is the difference between null and undefined?

Answer

  • undefined: A variable declared but not assigned a value.

  • null: A variable explicitly assigned an empty value.

let a;
console.log(a); // undefined
let b = null;
console.log(b); // null

Q16. What is an IIFE (Immediately Invoked Function Expression)?

Answer

An IIFE is a function that runs immediately after it is defined. It’s often used to create a private scope.

(function() {
console.log("IIFE executed!");
})();

Q17. What is Event Bubbling and Event Capturing?

Answer

  • Event Bubbling: The event starts from the innermost element and propagates outward.

  • Event Capturing: The event starts from the outermost element and propagates inward.

element.addEventListener("click", handler, true); // capturing
element.addEventListener("click", handler, false); // bubbling

Q18. What are Higher-Order Functions in JavaScript?

Answer

Higher-order functions are functions that can take other functions as arguments or return a function.

function multiply(factor) {
return function(x) {
return x * factor;
};
}
let double = multiply(2);
console.log(double(5)); // 10

Q19. What is a Callback Function?

Answer

A callback is a function passed into another function as an argument and executed later.

function greet(name, callback) {
console.log("Hello " + name);
callback();
}
greet("Arsalan", () => console.log("Welcome!"));

Q20. What is the difference between map(), forEach(), and filter()?

Answer

  • map(): Returns a new array after applying a function to each element.

  • forEach(): Executes a function on each element but doesn’t return a new array.

  • filter(): Creates a new array containing only the elements that meet a specific condition.

let nums = [1, 2, 3, 4];
console.log(nums.map(n => n * 2)); // [2,4,6,8]
console.log(nums.filter(n => n > 2)); // [3,4]
nums.forEach(n => console.log(n)); // 1 2 3 4
“Once you’re confident with these, continue to the next level for an even greater challenge.”

3) 10 Advance Level JavaScript Interview Questions

Q21. What are Promises in JavaScript?

Answer

A Promise signifies the eventual success or failure of an asynchronous task.

let promise = new Promise((resolve, reject) => {
setTimeout(() => resolve("Success!"), 1000);
});
promise.then(result => console.log(result));

For example, fetching user data from an API in React applications relies heavily on async/await.

Q22. What is Async/Await in JavaScript?

Answer

Async/await is a modern way to handle asynchronous code, making it look synchronous.

async function fetchData() {
let response = await fetch("https://api.example.com/data");
let data = await response.json();
console.log(data);
}
fetchData();

Q23. What is the Event Loop in JavaScript?

Answer

The Event Loop handles asynchronous operations. It continuously checks the call stack and the callback queue, executing tasks in order.

Q24. What are JavaScript Generators?

Answer

Generators are functions that can be paused and resumed using the yield keyword.

function* generator() {
yield 1;
yield 2;
yield 3;
}
let gen = generator();
console.log(gen.next().value); // 1

Q25. What is the difference between localStorage, sessionStorage, and cookies?

Answer

  • localStorage: Stores data with no expiration (browser-specific).

  • sessionStorage: Stores data for one session (deleted after tab/browser closes).

  • cookies: Small pieces of data stored with expiration, sent with every HTTP request.

Q26. What is Currying in JavaScript?

Answer

Currying is transforming a function with multiple arguments into a sequence of functions with one argument each.

function curry(a) {
return function(b) {
return function(c) {
return a + b + c;
};
};
}
console.log(curry(1)(2)(3)); // 6

Q27. What is Debouncing in JavaScript?

Answer

Debouncing ensures that a function is executed only after a specified delay, avoiding multiple calls.

function debounce(func, delay) {
let timeout;
return function(...args) {
clearTimeout(timeout);
timeout = setTimeout(() => func(...args), delay);
};
}

Q28. What is Throttling in JavaScript?

Answer

Throttling ensures that a function executes at most once in a given time interval.

function throttle(func, limit) {
let inThrottle;
return function(...args) {
if (!inThrottle) {
func(...args);
inThrottle = true;
setTimeout(() => inThrottle = false, limit);
}
};
}

Q29. What is the difference between Prototypal Inheritance and Classical Inheritance?

Answer

  • Prototypal Inheritance: Objects inherit directly from other objects (JavaScript model).

  • Classical Inheritance: Classes create objects and inheritance happens via class hierarchy (Java, C++).

Q30. What are WeakMap and WeakSet in JavaScript?

Answer

  • WeakMap: A collection of key-value pairs where keys must be objects, and references are weak.

  • WeakSet: A collection of objects stored weakly, preventing memory leaks.

“Once you’re confident with these, continue to the next level for an even greater challenge.”

4) 10 Tricky & Interesting JavaScript Questions

Q31. What will be the output of this code?

console.log([] + []);
console.log([] + {});
console.log({} + []);

Answer

  • [] + []"" (empty string)

  • [] + {}"[object Object]"

  • {} + []0 (interpreted as block + array)

Q32. What will this return?

console.log(typeof NaN);

Answer
Despite NaN standing for ‘Not a Number,’ its data type in JavaScript is actually number.

Q33. What is the difference between setTimeout(fn, 0) and fn()?

Answer

  • fn() → executes immediately.

  • setTimeout(fn, 0) → executes after the current call stack is cleared (pushed into event queue).

Q34. How can you make an object immutable in JavaScript?

Answer

Using Object.freeze()

const obj = { name: "Arsalan" };
Object.freeze(obj);
obj.name = "Ali";
console.log(obj.name); // Arsalan

Q35. What will happen here?

let x = 10;
let y = (x++, x + 5);
console.log(y);

Answer: 16
Explanation: (x++, x + 5) uses the comma operator → last expression (x + 5) is returned.

Q36. Can you compare two objects directly in JavaScript?

console.log({a:1} === {a:1});

Answer: false
This happens since objects are compared based on their reference, not their actual value.

Q37. How can you clone an object in JavaScript?

Answer

  • Shallow clone:

let obj = {a:1, b:2};
let clone = {...obj};
  • Deep clone:

let deep = JSON.parse(JSON.stringify(obj));

Q38. What will this output?

console.log(0.1 + 0.2 === 0.3);

Answer: false
Because floating-point arithmetic in JavaScript is not exact (0.1 + 0.2 = 0.30000000000000004).

Q39. How can you check if a variable is an array?

Answer

Array.isArray([1,2,3]); // true

Trick: typeof [1,2,3] returns "object", not "array".

Q40. What is the difference between function foo(){} and let foo = function(){}?

Answer

  • function foo(){} → function declaration, hoisted to the top.

  • let foo = function(){} → function expression, not hoisted.

Mastering these JavaScript interview questions will not only help you crack interviews but also make you a better developer in real projects.

💡 Tip: Don’t just memorize these questions. Try coding them out, tweak the examples, and create your own variations. That’s how you’ll build real confidence.

Remember: interviews are not just about giving the “right” answers. They’re about showing how well you think, explain, and solve problems under pressure.

Which tricky JavaScript concept has confused you the most? Let me know in comments! 👇

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top

Share

Post Link 👇

Contact Form

We contact you please fill this form and submit it