Krazy Kaksha

Interview Prep

JavaScript Interview Questions and Answers for Freshers (2026)

Krazy Kaksha 6 min read

JavaScript Interview Questions and Answers for Freshers (2026)

JavaScript is asked in almost every web developer, frontend and full stack interview, and even in many service company rounds. This list covers the questions freshers get most often, with short answers you can say in an interview and small code examples.

Quick summary

LevelTopics to prepare
BasicsData types, var vs let vs const, == vs ===, null vs undefined
CoreHoisting, scope, closures, this, arrow functions
AsyncCallbacks, promises, async/await, event loop
Arrays and objectsmap, filter, reduce, spread, destructuring, copies
BrowserDOM, events, bubbling, localStorage

Basics

1. What is JavaScript?
JavaScript is a lightweight, interpreted (JIT compiled) programming language used to make web pages interactive. Today it also runs on servers through Node.js.

2. What are the data types in JavaScript?
Primitive types: string, number, bigint, boolean, undefined, null and symbol. Everything else is an object (arrays, functions, dates and so on).

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

Pointvarletconst
ScopeFunctionBlockBlock
Re-declareYesNoNo
Re-assignYesYesNo
HoistingHoisted as undefinedHoisted, in temporal dead zoneHoisted, in temporal dead zone

4. What is the difference between == and ===?
== compares values after type conversion, so 5 == "5" is true. === compares value and type, so 5 === "5" is false. Always prefer ===.

5. What is the difference between null and undefined?
undefined means a variable is declared but no value is given. null is a value you set on purpose to say “no value”. typeof null returns “object”, which is a known old bug.

6. What is NaN?
NaN means “Not a Number”, for example the result of "abc" * 2. Check it with Number.isNaN(x).

Core concepts

7. What is hoisting?
Hoisting means declarations are moved to the top of their scope before the code runs. Function declarations are fully hoisted. var is hoisted with the value undefined. let and const are hoisted but cannot be used before the declaration line (temporal dead zone).

8. What is scope?
Scope decides where a variable can be used. JavaScript has global scope, function scope and block scope.

9. What is a closure?
A closure is a function that remembers the variables of its outer function even after the outer function has finished.

function counter() { let c = 0; return () => ++c; }
const next = counter(); next(); next(); // 2

Closures are used for data privacy, counters, and in callbacks.

10. What is the “this” keyword?
this refers to the object that is calling the function. In a method it is the object, in a normal function (non strict mode) it is the global object, and in strict mode it is undefined.

11. How are arrow functions different from normal functions?
Arrow functions are shorter, do not have their own this (they take it from the outer scope), have no arguments object and cannot be used as constructors with new.

12. What are call, apply and bind?
All three set the value of this. call passes arguments one by one, apply passes them as an array, and bind returns a new function with this fixed.

13. What is a higher-order function?
A function that takes another function as an argument or returns a function. Examples: map, filter, reduce, setTimeout.

14. What is prototypal inheritance?
Every object has a hidden link called the prototype. If a property is not found on the object, JavaScript looks for it in the prototype chain. Classes in JavaScript are built on top of this.

Asynchronous JavaScript

15. Is JavaScript single-threaded?
Yes. It runs one task at a time on one main thread. Async work like timers and network calls is handled by the browser or Node.js, and the results come back through the event loop.

16. What is the event loop?
The event loop checks if the call stack is empty. When it is, it first runs all microtasks (promise callbacks), then takes the next macrotask (setTimeout, events) from the queue.

Classic output question:

console.log(1); setTimeout(() => console.log(2), 0); Promise.resolve().then(() => console.log(3)); console.log(4);

Output: 1, 4, 3, 2.

17. What is a callback and what is callback hell?
A callback is a function passed to another function to run later. Many nested callbacks make the code hard to read, which is called callback hell. Promises and async/await solve this.

18. What is a promise?
A promise is an object that represents a value that will come in the future. It has three states: pending, fulfilled and rejected. Use .then() for success and .catch() for errors.

19. What is async/await?
It is a cleaner way to write promise code. An async function always returns a promise, and await pauses that function until the promise settles. Use try/catch for errors.

20. What is the difference between Promise.all and Promise.allSettled?
Promise.all fails as soon as one promise fails. Promise.allSettled waits for all and gives the result of each, success or failure.

Arrays and objects

21. What is the difference between map, filter and reduce?
map changes each item and returns a new array of the same length. filter returns only the items that pass a test. reduce turns the array into a single value, like a sum.

22. What is the spread operator?
... spreads the items of an array or object. Example: const b = [...a, 4] or const user2 = {...user, age: 21}.

23. What is destructuring?
Taking values out of arrays or objects into variables: const {name, age} = user; or const [first, second] = list;.

24. What is the difference between shallow copy and deep copy?
A shallow copy (spread, Object.assign) copies only the top level, so nested objects are still shared. A deep copy copies everything. Use structuredClone(obj) for a deep copy.

25. How do you remove duplicates from an array?
const unique = [...new Set(arr)];

Browser and DOM

26. What is the DOM?
The Document Object Model is a tree of objects that represents the HTML page. JavaScript uses it to read and change the page.

27. What is event bubbling and capturing?
In bubbling, an event starts at the clicked element and moves up to its parents. In capturing it goes from the top down. addEventListener uses bubbling by default; pass true or {capture: true} for capturing.

28. What is event delegation?
Adding one listener on a parent instead of many on each child. It uses bubbling and is faster for long lists.

29. What is the difference between localStorage, sessionStorage and cookies?
localStorage keeps data with no expiry. sessionStorage keeps it only until the tab is closed. Cookies are small, can have an expiry and are sent to the server with every request.

30. What are debouncing and throttling?
Debouncing runs a function only after the user stops an action for some time (search box). Throttling runs it at most once in a fixed time (scroll event).

Coding questions asked often

QuestionHint
Reverse a strings.split('').reverse().join('')
Check palindromeCompare string with its reverse
Find the largest number in an arrayMath.max(...arr)
Count vowelsLoop or regex /[aeiou]/gi
Flatten a nested arrayarr.flat(Infinity)
Write a debounce functionsetTimeout + clearTimeout inside a closure

Tips for the interview

  • Explain with a tiny example. Interviewers love one line of code.
  • Event loop output questions are very common. Practise 4 or 5 of them.
  • Know the basics of one framework (React is the most asked), but JavaScript fundamentals come first.
  • Be honest if you do not know something, and say how you would find it.

Related posts

Doubts? Ask here

Leave a comment

Your email is not shown. Comments appear after a quick check.