JavaScript Interview Questions for Freshers: 25 Questions With Answers
25 fresher-level JavaScript interview questions with complete answers, output-prediction snippets, a topic-weighting table and a 7-day plan.
Last updated: 13 October 2026 · By the Asuraa Team
Quick answer: The JavaScript interview questions freshers face most are var vs let vs const, hoisting, == vs ===, closures, the this keyword, the event loop, promises and async/await, plus browser topics like event delegation and debounce. Expect output-prediction snippets: per MDN, promise callbacks are microtasks and run before setTimeout callbacks, so a resolved promise logs before a 0 ms timer. Answer with a definition, a reason and a short example.
Key takeaways
- Fresher JavaScript interviews focus on types and variables, functions and closures, asynchronous code, objects and browser events.
- MDN's let reference explains that let and const variables sit in a temporal dead zone until their declaration runs, and accessing them early throws a ReferenceError.
- MDN's execution model page states that microtasks such as promise callbacks run before the next task, so a resolved promise logs before a setTimeout callback with a 0 ms delay.
- Promise.all rejects on the first rejection, Promise.allSettled never rejects, Promise.any rejects with an AggregateError only if all inputs reject, and Promise.race follows the first promise to settle.
- Asuraa's October 2026 job market report found JavaScript, React or Node named in 17.0% of the fresher listings it analysed.
JavaScript interviews for freshers test four things: how variables and types behave, how functions and scope work, how asynchronous code runs, and how the browser handles events. The 25 questions below are grouped in that order, each with a complete answer you can say in under a minute. JavaScript skills are visible in real hiring too: Asuraa's October 2026 job market report found JavaScript, React or Node named in 17.0% of the fresher listings it analysed.
Which JavaScript topics carry the most weight in fresher interviews?
Scope, closures and asynchronous behaviour carry the most weight, because they produce the "predict the output" questions interviewers love.
| Area | Typical questions | What interviewers check |
|---|---|---|
| Types and variables | var vs let vs const, == vs ===, hoisting | Whether you can predict behaviour, not just define it |
| Functions and scope | Closures, this, arrow functions, bind | Mental model of execution context |
| Async | Event loop, promises, async/await, output order | Whether you understand non-blocking code |
| Objects | Prototypes, shallow vs deep copy, destructuring | Data handling in real apps |
| Browser | Event delegation, debounce, storage | Practical front-end experience |
For other subjects, the interview questions by subject guide lists every question bank in one place.
What are the basic JavaScript questions on types and variables?
These six questions open most JavaScript rounds.
1. What are the data types in JavaScript?
JavaScript has seven primitive types: string, number, bigint, boolean, undefined, symbol and null. Everything else is an object, including arrays and functions. Primitives are copied by value and are immutable; objects are passed around by reference. typeof helps identify types, with a couple of well-known quirks.
2. What is the difference between var, let and const?
var is function-scoped and can be redeclared; let and const are block-scoped and cannot be redeclared in the same scope. const prevents reassignment of the binding, but an object declared with const can still have its properties changed. MDN's let reference also notes that a top-level let does not create a property on the global object, unlike var. Default to const, use let when you must reassign, and avoid var.
3. What is hoisting, and what is the temporal dead zone?
Hoisting means declarations are processed before code runs. A var is hoisted and initialised to undefined, so reading it early gives undefined. A let or const variable exists from the start of its block but cannot be accessed until its declaration line runs; that gap is the temporal dead zone, and access inside it throws a ReferenceError. Function declarations are hoisted with their body, so you can call them before they appear.
console.log(a); // undefined
console.log(b); // ReferenceError
var a = 1;
let b = 2;
4. What is the difference between == and ===?
=== (strict equality) returns true only if both operands have the same type and value; == converts types before comparing. MDN's strict equality page shows that "1" == 1 is true while "1" === 1 is false. For objects, both compare references, so two separate objects with the same content are not equal. Use === by default.
5. What is the difference between null and undefined?
undefined means a variable was declared but never assigned, or a property does not exist. null is a value a developer assigns on purpose to mean "no value". null == undefined is true but null === undefined is false. typeof null returns "object", a long-standing language quirk.
6. Why is NaN === NaN false, and how do you check for NaN?
NaN ("not a number") is the result of invalid numeric operations like 0 / 0 or Number("abc"). Strict equality returns false whenever either operand is NaN, even itself, as MDN's equality page states. Use Number.isNaN(x) to test it; the older global isNaN() converts its argument first and gives surprising results such as isNaN("abc") being true.
What questions are asked on functions, scope and closures?
This group decides most JavaScript interviews.
7. What is a closure? Give an example.
A closure is a function bundled with references to the variables of the scope where it was created, so it can still use them after that outer function has returned. MDN's closures guide notes closures are created every time a function is created. They power data privacy, counters, memoisation and event handlers.
function counter() {
let count = 0;
return () => ++count;
}
const next = counter();
next(); next(); // 2
8. Why does a loop with var and setTimeout print the same number?
With var, the loop variable is function-scoped, so every callback closes over one shared variable that holds its final value by the time callbacks run. Switching to let creates a fresh binding per iteration, so each callback sees its own value. This is the classic closure pitfall MDN uses as an example.
for (var i = 0; i < 3; i++) setTimeout(() => console.log(i)); // 3 3 3
for (let j = 0; j < 3; j++) setTimeout(() => console.log(j)); // 0 1 2
9. How does the this keyword work?
this depends on how a function is called, not where it is written. In a method call obj.fn(), this is obj; in a plain function call it is undefined in strict mode; with new it is the new object; and in an event listener it is usually the element. Arrow functions do not get their own this; they use the this of the surrounding scope.
10. What is the difference between arrow functions and regular functions?
Arrow functions have shorter syntax, inherit this and arguments from the enclosing scope, and cannot be used as constructors with new. That makes them ideal for callbacks inside methods but unsuitable as object methods that need their own this. Regular functions get their own this based on the call site.
11. What do call, apply and bind do?
All three set this explicitly. call(thisArg, a, b) invokes the function immediately with arguments listed individually; apply(thisArg, [a, b]) invokes it with an array of arguments; bind(thisArg) returns a new function with this permanently set, to be called later. bind is common when passing a method as a callback.
12. What are higher-order functions? Explain map, filter and reduce.
A higher-order function takes a function as an argument or returns one. map transforms each element into a new array, filter keeps elements that pass a test, and reduce combines elements into a single value. None of them mutate the original array.
const total = cart
.filter(item => item.inStock)
.map(item => item.price * item.qty)
.reduce((sum, x) => sum + x, 0);
What async JavaScript questions should freshers expect?
Expect at least one "what is the output" question here.
13. What is the event loop?
JavaScript runs one job at a time on a single thread; when the call stack is empty, the event loop picks the next job from a queue. MDN's execution model page explains that jobs are split into tasks (such as setTimeout callbacks and UI events) and microtasks (such as promise callbacks), and the microtask queue is drained before the next task runs. Each job runs to completion, so a long loop blocks clicks and rendering.
14. What does this code print, and why?
console.log("A");
setTimeout(() => console.log("B"), 0);
Promise.resolve().then(() => console.log("C"));
console.log("D");
It prints A, D, C, B. A and D are synchronous. The promise callback is a microtask, so it runs as soon as the current script finishes, before the setTimeout callback, which is a task even with a 0 ms delay.
15. What is a Promise and what are its states?
A promise represents the eventual result of an asynchronous operation. Per MDN's Promise reference, it is pending at first and then settles as either fulfilled or rejected. then handles success, catch handles errors and finally runs either way; each returns a new promise, which is what makes chaining possible.
16. What is the difference between Promise.all, allSettled, any and race?
Promise.all fulfils with an array of all results, but rejects as soon as any input rejects. Promise.allSettled waits for every promise and never rejects, giving you each outcome. Promise.any fulfils with the first success and rejects with an AggregateError only if all reject. Promise.race settles the same way as whichever promise settles first, success or failure.
17. How do async and await work?
An async function always returns a promise; await pauses that function until a promise settles and then gives back the value or throws the rejection. It makes asynchronous code read top to bottom, and errors are handled with ordinary try/catch. Use Promise.all with await when calls are independent, so they run in parallel.
async function loadProfile(id) {
try {
const res = await fetch(`/api/users/${id}`);
return await res.json();
} catch (err) {
console.error(err);
}
}
What object and ES6 questions come up?
18. What is prototypal inheritance?
Every object has an internal link to another object, its prototype, and property lookups walk up this chain until they find the property or reach null. Methods defined on Array.prototype are why every array has map and push. The class syntax is a cleaner way to write the same prototype-based inheritance, not a separate model.
19. What is the difference between a shallow copy and a deep copy?
A shallow copy ({...obj} or Object.assign) copies top-level properties, but nested objects are still shared, so changing them affects the original. A deep copy duplicates every nested level. structuredClone(obj) makes deep copies of most plain data; JSON.parse(JSON.stringify(obj)) also works but drops functions, undefined and dates.
20. What are destructuring, spread and rest?
Destructuring pulls values out of arrays or objects into variables: const { name, city } = user;. The spread operator ... expands an array or object, for copying or merging. Rest uses the same ... syntax to collect remaining items into an array, such as function sum(...nums).
21. What is the difference between ES modules export and import styles?
A module can have many named exports, imported with braces using the exact name, and at most one default export, imported with any name. Modules have their own scope, run in strict mode and load once even if imported many times. Example: import React, { useState } from "react"; takes the default and one named export.
What browser and DOM questions do freshers face?
22. What is event bubbling and event delegation?
When an event fires on an element, it bubbles up through its ancestors, triggering their listeners too. Event delegation uses this: attach one listener to a parent and check event.target to handle clicks on many children, including ones added later. event.stopPropagation() stops the bubbling.
23. What is the difference between debounce and throttle?
Debounce waits until events stop for a set time before running the function once, which suits search boxes that should query after typing pauses. Throttle runs the function at most once per interval no matter how often the event fires, which suits scroll or resize handlers. Both reduce wasted work.
function debounce(fn, ms) {
let t;
return (...args) => { clearTimeout(t); t = setTimeout(() => fn(...args), ms); };
}
24. What is the difference between localStorage, sessionStorage and cookies?
localStorage keeps data with no expiry for the origin until it is cleared; sessionStorage keeps data only for the lifetime of the tab. Cookies are small, can carry an expiry, and are sent to the server with every matching request, which is why they are used for sessions. Never store passwords or sensitive tokens in localStorage, because any script on the page can read it.
25. What is the difference between synchronous and asynchronous code, and what is callback hell?
Synchronous code runs line by line and blocks until each step finishes; asynchronous code starts an operation and continues, handling the result later through a callback, promise or await. Callback hell is deeply nested callbacks that are hard to read and handle errors in. Promises and async/await flatten that nesting into readable sequences.
How should you revise JavaScript in 7 days before the interview?
Spend one day per area, run every snippet in the browser console, and end with timed output-prediction practice. The technical interview preparation guide explains how to talk through code during the round.
- Day 1: Types and variables. Types, var/let/const, hoisting, == vs ===, null vs undefined.
- Day 2: Functions. Closures, this, arrow functions, call/apply/bind. Write the counter and loop examples from memory.
- Day 3: Arrays and objects. map/filter/reduce, destructuring, spread, shallow vs deep copy.
- Day 4: Async. Event loop, promises, async/await. Predict output for five mixed setTimeout and promise snippets.
- Day 5: Browser. DOM selection, event delegation, debounce and throttle, storage.
- Day 6: Coding. Solve six problems in JavaScript: reverse a string, remove duplicates with a Set, flatten an array, group by key, implement debounce, fetch and render a list.
- Day 7: Mock and project. Do a mock interview and prepare a walkthrough of one JavaScript project, including one bug you fixed.
If you need structured learning first, read how to learn JavaScript for jobs; if your target is front-end roles, follow up with React interview questions for freshers.
What do most guides on JavaScript interview questions get wrong?
Most guides teach definitions, but fresher JavaScript rounds are mostly "predict the output" and "fix this snippet". Knowing that let is block-scoped is not enough; you need to explain why the var loop prints 3 3 3. Many lists also say let is "not hoisted", which is imprecise: the binding exists from the start of the block but sits in the temporal dead zone until its declaration runs. Finally, guides often skip microtasks, so candidates assume setTimeout(fn, 0) runs before a resolved promise callback. Practise in the console until the output never surprises you.
Related guides
- Interview Questions by Subject: Java, Python, SQL, DSA, Cloud, AI
- Java Interview Questions for Freshers: 25 Questions With Answers
- React Interview Questions for Freshers: 22 Questions With Answers
- DBMS Interview Questions for Freshers: 25 Questions With Answers
FAQ
What are the most important JavaScript topics for a fresher interview?
Focus on var vs let vs const, hoisting and the temporal dead zone, == vs ===, closures, the this keyword, arrow functions, the event loop, promises and async/await, array methods like map, filter and reduce, and browser topics such as event delegation and debounce. Most rounds include at least one output-prediction snippet on closures or async order.
Why does a promise callback run before setTimeout with 0 ms?
Promise callbacks are microtasks and setTimeout callbacks are tasks. According to MDN's execution model page, the engine drains the whole microtask queue as soon as the current job finishes, before taking the next task. So even a 0 ms timer waits until all pending promise callbacks have run.
How do I explain closures simply in an interview?
Say that a closure is a function that remembers the variables from the scope where it was created, even after that outer function has returned. Then show a counter function that returns an inner function incrementing a private count variable. Mention one real use, such as data privacy or event handlers, and the var-in-a-loop pitfall.
Do freshers need to know TypeScript for JavaScript interviews?
Not usually for the JavaScript round itself, which tests core language behaviour. Many front-end job descriptions do list TypeScript, so knowing basic types, interfaces and why static typing catches bugs is a useful extra. Prepare core JavaScript first, because TypeScript questions assume you already understand it.
Are coding questions asked in JavaScript interviews for freshers?
Yes. Common tasks include reversing a string, removing duplicates with a Set, flattening a nested array, grouping objects by a key, implementing debounce, and fetching data from an API and rendering it. Practise in a plain editor and explain your approach aloud as you write.
Is var still used in modern JavaScript?
Rarely in new code. let and const are block-scoped and avoid the hoisting and redeclaration surprises that var causes, so most style guides recommend const by default and let when reassignment is needed. You still need to understand var because older codebases and interview output questions use it.
Final thoughts
JavaScript interviews reward freshers who can predict what code will do and explain why, especially around closures, this and async order. Run every snippet in this list in your browser console until the output is obvious to you, then connect each concept to a project you built. When you are ready to apply, browse front-end and full-stack roles on Asuraa jobs.
Related articles
Remote Software Engineering Internships in India: Where to Look
Where remote SDE internships in India really come from, what they pay, which open-source programmes count, and a 4-week plan to get shortlisted.
Remote Data Science Internships for Freshers: How to Find Real Ones
Real remote data science internships come from startups, consultancies and open-source programmes. Here is where to find them, what they pay and how to prepare in 4 weeks.
Interview Questions by Subject: Java, Python, SQL, DSA, Cloud, AI
Every interview question set in one place, organised by subject and role: core CS, programming languages, web and testing, data and analytics, AI and ML, cloud, DevOps and HR rounds.
Projects and Portfolio Guide for Freshers: Data, Software and AI
Choose the right projects for data analyst, data scientist, ML, web and software roles, build them on real public data or APIs, and present them so recruiters notice.