Top 25 javaScript interview questions for freshers
25 JavaScript interview questions freshers actually get asked, with short answers, examples and the follow-ups interviewers like to try.

If you are preparing for your first developer job, you have probably noticed that JavaScript interview questions for freshers follow a pattern. Interviewers rarely ask exotic tricks. They ask the same core ideas again and again: scope, closures, this promises, array methods and a handful of output-prediction puzzles.
This list brings together 25 of those questions, with short answers, small examples and the follow-up questions interviewers like to try. Use it for JS interview prep whether you are aiming for a frontend role, a full-stack role or a campus placement. Most of these JavaScript interview questions and answers are also useful for frontend interview questions in 2026, because the language fundamentals change slowly even as frameworks come and go.
How to use this list
Reading answers is not the same as being able to give them. Here is a better way to use this page.
Cover the answer and try first. Read the question, say your answer out loud, then compare.
Run the examples. Paste each snippet into your browser console and change it. Seeing the result yourself makes it stick.
Explain in your own words. If you can only repeat the answer from the page, you have not understood it yet.
Prepare for follow-ups. Each question has a “Follow-up” line, because interviewers often ask a second question to see how deep your understanding goes.
Keep answers short. A good interview answer is usually 20 to 40 seconds: a clear definition, a small example, and one practical point.
Basics: var/let/const, types, equality, hoisting
1. What is the difference between var, let and const?
var is function-scoped and can be redeclared. let and const are block-scoped, so they exist only inside the nearest pair of curly braces. let can be reassigned, while const cannot be reassigned after it is declared. Note that const stops reassignment, not mutation, so you can still change the contents of a const array or object.
js
const user = { name: "Asha" }; user.name = "Ravi"; // allowed user = {}; // TypeError
Follow-up: Which would you use by default? Use const by default, let when the value must change, and avoid var in new code.
2. What are the data types in JavaScript?
There are seven primitive types: string, number, bigint, boolean, undefined, null and symbol. Everything else is an object, including arrays and functions. Primitives are immutable and compared by value, while objects are compared by reference.
Follow-up: What does typeof null return? It returns "object". This is a long-standing quirk of the language, not a sign that null is an object.
3. What is the difference between == and ===?
== compares values after converting them to a common type (type coercion). === compares both value and type, with no conversion. Most teams prefer === because it avoids surprises.
js
console.log(5 == "5"); // true console.log(5 === "5"); // false
Follow-up: How do you check for NaN? NaN === NaN is false, so use Number.isNaN(value).
4. What is hoisting?
Hoisting means declarations are processed before the code runs, so you can use some of them before the line where they appear. Function declarations are fully hoisted, so you can call them early. var variables are hoisted and set to undefined . let and const are hoisted too, but you cannot use them before their declaration.
js
console.log(a); // undefined var a = 5;
Follow-up: What happens if you do the same with let? You get a ReferenceError. This leads to the next question.
5. What is the temporal dead zone?
It is the period between the start of a block and the line where a let or const variable is declared. During that time, the variable exists but cannot be accessed, and touching it throws a ReferenceError. It helps catch bugs where a variable is used too early.
Follow-up: Is a function declaration affected by it? No. Function declarations are fully hoisted and can be called before they appear.
6. What is the difference between null and undefined?
undefined means a variable has been declared but has no value yet, or a function returned nothing. null is an intentional “no value” that you assign yourself. They are loosely equal (null == undefined is true) but not strictly equal.
Follow-up: When would you use null? To signal on purpose that something is empty, such as resetting a field.
Functions, scope and closures
7. What is scope in JavaScript?
Scope decides where a variable can be accessed. There is global scope, function scope and block scope. Inner scopes can read variables from outer scopes, but not the other way around. JavaScript looks for a variable in the current scope first, then moves outward. This chain is called the scope chain.
Follow-up: What is lexical scope? It means scope is decided by where code is written, not where it is called.
8. What is a closure?
A closure is a function that remembers the variables from the place where it was created, even after that outer function has finished running.
js
function makeCounter() { let count = 0; return function () { count++; return count; }; } const next = makeCounter(); console.log(next()); // 1 console.log(next()); // 2
Here, the inner function keeps access to count, and nothing outside can change it directly.
Follow-up: Where are closures used in real life? Private variables, event handlers, function factories and memoization.
9. What is the difference between function declarations, function expressions and arrow functions?
A function declaration (function add() {}) is hoisted, so you can call it before its definition. A function expression (const add = function () {}) is not hoisted in the same way. An arrow function (const add = () => {}) has shorter syntax and, importantly, does not have its own this or arguments, and it cannot be used with new.
Follow-up: Can you use an arrow function as a constructor? No, it will throw an error.
10. What is a higher-order function?
A function that takes another function as an argument, returns a function, or both. map, filter, reduce and setTimeout are common examples. The function you pass in is called a callback.
js
const doubled = [1, 2, 3].map((n) => n * 2); // [2, 4, 6]
Follow-up: Can you write your own higher-order function? A good answer is a small function that returns another function, like the counter above.
11. What is an IIFE and why would you use it?
An IIFE (Immediately Invoked Function Expression) is a function that runs as soon as it is defined. It creates a private scope, so variables inside do not leak into the global scope.
js
(function () { const secret = "hidden"; console.log(secret); })();
Follow-up: Is it still needed today? It is less common now because let, const and modules give you block and file scope, but you will still see it in older code.
this, call/apply/bind
12. How does this work in JavaScript?
The value of this depends on how a function is called, not where it is written. In a method call (user.greet()), this is the object before the dot. In a plain function call, this is undefined in strict mode, or the global object otherwise. With new, this is the new object. With call, apply or bind, you set this yourself.
js
const user = { name: "Asha", greet() { console.log(this.name); }, }; user.greet(); // Asha const fn = user.greet; fn(); // undefined (this is lost)
Follow-up: Why did this get lost in the example? Because fn() is a plain call, so this no longer points to user.
13. What is the difference between call, apply and bind?
All three let you choose this. call runs the function immediately with arguments passed one by one. apply runs it immediately with arguments in an array. bind does not run it. It returns a new function with this fixed.
js
function intro(city) { console.log(this.name + " from " + city); } const person = { name: "Asha" }; intro.call(person, "Kota"); intro.apply(person, ["Kota"]); const bound = intro.bind(person); bound("Kota");
Follow-up: When is bind useful? When you pass a method as a callback and need to keep its this.
14. How does this behave in arrow functions?
Arrow functions do not have their own this. They use the this of the surrounding scope where they were created. This makes them handy for callbacks inside methods, but a poor choice for object methods that need their own this. Also, call, apply and bind cannot change an arrow function’s this.
Follow-up: Would you write an object method as an arrow function? Usually not, because this will not point to the object.
Async JavaScript: callbacks, promises, async/await
15. What is the event loop?
JavaScript runs one thing at a time on a single thread. Slow tasks like timers and network requests are handled outside the main thread, and their callbacks wait in queues. The event loop checks whether the call stack is empty and, if so, moves the next waiting task onto it. Promise callbacks go into the microtask queue, which is processed before the next timer callback in the macrotask queue.
Follow-up: Which runs first, a promise callback or a setTimeout with 0 delay? The promise callback, because microtasks run first.
16. What is a callback, and what is callback hell?
A callback is a function passed to another function to be called later, such as after a timer or a request. Callback hell is what happens when you nest many callbacks inside each other, making code hard to read and handle errors in. Promises and async/await solve this.
Follow-up: How do you avoid it? Use promises or async/await, and break the code into smaller named functions.
17. What is a promise?
A promise is an object that represents a value that will be available later. It has three states: pending, fulfilled (success) and rejected (failure). You handle results with .then() and errors with .catch().
js
fetch("/api/data") .then((res) => res.json()) .then((data) => console.log(data)) .catch((err) => console.error(err));
Follow-up: What does .then() return? A new promise, which is why you can chain them.
18. What is async/await, and how do you handle errors?
async and await are syntax for working with promises in a style that reads like normal code. An async function always returns a promise, and await pauses that function until the promise settles. Handle errors with try/catch.
js
async function loadData() { try { const res = await fetch("/api/data"); const data = await res.json(); return data; } catch (err) { console.error(err); } }
Follow-up: Does await block the whole program? No. It pauses only the current async function, and other code keeps running.
19. What is the difference between Promise.all and Promise.allSettled?
Promise.all takes an array of promises and resolves when all succeed, but it rejects as soon as any one fails. Promise.allSettled waits for every promise to finish and gives you the status of each, whether it succeeded or failed.
Follow-up: When would you pick allSettled? When you want results from every request even if some of them fail.
Arrays, objects and ES6+ features
20. What is the difference between map, filter, reduce and forEach?
map returns a new array by transforming each item. filter returns a new array with only the items that pass a test. reduce combines all items into a single value. forEach just runs a function for each item and returns nothing. map, filter and reduce do not change the original array.
js
const nums = [1, 2, 3, 4]; nums.map((n) => n * 2); // [2, 4, 6, 8] nums.filter((n) => n % 2 === 0); // [2, 4] nums.reduce((sum, n) => sum + n, 0); // 10
Follow-up: Can you use reduce to find the maximum? Yes, by keeping the larger value as you go.
21. What is the difference between a shallow copy and a deep copy?
A shallow copy copies only the top level. Nested objects are still shared between the original and the copy. A deep copy copies everything, so changes to one do not affect the other. The spread operator and Object.assign make shallow copies. For a deep copy, use structuredClone(obj) in modern environments.
js
const a = { x: 1, nested: { y: 2 } }; const b = { ...a }; b.nested.y = 99; console.log(a.nested.y); // 99 (shared)
Follow-up: What is wrong with JSON.parse(JSON.stringify(obj))? It drops functions and undefined and turns dates into strings.
22. What are destructuring, the spread operator and rest parameters?
Destructuring pulls values out of arrays or objects into variables. The spread operator (...) expands an array or object into individual items. Rest parameters (...args) do the opposite in a function definition and collect the remaining arguments into an array.
js
const [first, second] = [10, 20]; const { name } = { name: "Asha", age: 21 }; const merged = [...[1, 2], ...[3, 4]]; // [1, 2, 3, 4] function sum(...nums) { return nums.reduce((a, b) => a + b, 0); }
Follow-up: Can you set a default value while destructuring? Yes, for example const { age = 18 } = user.
23. What is the difference between for...in and for...of?
for...in loops over the keys (property names) of an object. for...of loops over the values of an iterable, such as an array, string, Map or Set. Use for...of for arrays.
js
const arr = ["a", "b"];
for (const i in arr) console.log(i); // "0", "1"
for (const v of arr) console.log(v); // "a", "b"Follow-up: Can you use for...of on a plain object? No, because plain objects are not iterable. Use Object.keys, Object.values or Object.entries first.
24. What are Set and Map?
A Set stores unique values, so it is a quick way to remove duplicates. A Map stores key-value pairs like an object, but its keys can be any type, and it remembers insertion order.
js
const unique = [...new Set([1, 2, 2, 3])]; // [1, 2, 3]
const map = new Map();
map.set("a", 1);
console.log(map.get("a")); // 1Follow-up: When would you pick a Map over an object? When keys are not simple strings, or when you add and remove entries often.
25. What are event bubbling and event delegation?
When an event happens on an element, it first runs there and then bubbles up through its parents. Event delegation uses this: instead of adding a listener to every child, you add one listener on a parent and check event.target to see which child was clicked. It saves memory and also works for items added later.
Follow-up: How do you stop bubbling? Call event.stopPropagation(), though you should use it sparingly.
Quick self-test questions
Try to answer these before looking at the solutions. They are the kind of output-prediction questions freshers often get.
Question A
js
console.log(typeof null);
console.log(0.1 + 0.2 === 0.3);
console.log("5" + 3);
console.log("5" - 3);Question B
js
console.log(a);
var a = 5;Question C
js
for (var i = 0; i < 3; i++) {
setTimeout(() => console.log(i), 0);
}What changes if you replace var with let?
Question D
js
console.log("A");
setTimeout(() => console.log("B"), 0);
Promise.resolve().then(() => console.log("C"));
console.log("D");Answers
A:
"object",false,"53",2. The first is a language quirk, the second is floating-point precision, and the last two show that+joins strings while-converts to numbers.B:
undefined, becausevaris hoisted and set toundefined.C: It prints
3, 3, 3, because all three callbacks share onevar i, which is already 3 when they run. Withlet, each loop gets its owni, so it prints0, 1, 2.D:
A, D, C, B. The synchronous logs run first, then the promise callback (microtask), then the timer callback.
if you got all four right and could explain why, you are in good shape for most fresher-level screening rounds.
What to do after reading
Reading 25 answers is a start, not the finish line. Here is a simple plan for the next week.
Pick the questions you hesitated on. Mark them and rewrite the answer in your own words.
Type the examples. Do not copy and paste. Type them, run them and change them.
Practise out loud. Explain closures,
thisand the event loop to a friend or to a mirror. Time yourself.Revise with problems. Solve a few small problems each day that use
map,filter,reduce, promises and closures.Build a small project. Questions make sense faster when you have used the ideas, for example in a to-do app or a weather app that fetches data.
Mock interview. Ask someone to pick random questions from this list and add their own follow-ups.
FAQs
How many JavaScript questions should a fresher prepare?
There is no fixed number. Knowing the topics on this list well, and being able to explain them with a small example, matters more than memorising hundreds of questions.
Are these JavaScript interview questions enough for a job?
They cover the common fundamentals, but interviews usually also include data structures and algorithms, projects and sometimes a framework like React. Treat this list as one important part of your preparation.
Do I need to learn ES6 features for interviews?
Yes. Arrow functions, destructuring, spread, promises, template literals and modules are used everywhere in modern code and are commonly asked.
What is the most commonly asked JavaScript topic?
Closures, this, promises and async/await, hoisting and array methods come up very often. If you are short on time, start with those.
Should I learn React before JavaScript interviews?
Learn JavaScript fundamentals first. React interviews assume you already understand scope, closures, this, async code and array methods, and weak fundamentals make React harder.
How do I answer if I do not know a question?
Say what you do know, explain how you would find out, and think out loud. Interviewers usually care about how you reason, and a confident “I am not sure, but I think it works like this” is better than silence.
How long does it take to prepare for JavaScript interviews?
If you already know the basics, two to four weeks of steady practice is a reasonable time to feel prepared. If you are new to JavaScript, spend more time on the fundamentals first.
Where can I practise these questions?
Use quizzes, coding problems and mock interviews. Write down the questions you miss and revisit them after a few days.
Test yourself and keep going
Now that you have gone through the questions, find out what you actually remember. Test yourself with the JavaScript quizzes on The Zift, then browse frontend openings. Use what you got wrong as your revision list for the coming week.
