Top 30 JavaScript Interview Questions & Answers
1. What is JavaScript?
JavaScript is a high-level, interpreted language used to create dynamic and interactive web content. Runs in browsers and on servers via Node.js.
2. Difference between var, let, and const
-
var: function-scoped, can be redeclared -
let: block-scoped, can be updated but not redeclared -
const: block-scoped, cannot be updated
3. Data types in JavaScript
-
Primitive: string, number, boolean, undefined, null, symbol, bigint
-
Non-primitive: object, array, function
4. undefined vs null
-
undefined: variable declared but not assigned -
null: explicit empty value
5. typeof operator
Returns the type of a variable:
6. Template literals
Allows embedded expressions and multi-line strings:
7. Difference between == and ===
-
==: value comparison (with type coercion) -
===: strict comparison (no type coercion)
8. Is JavaScript dynamically typed?
Yes. Variables can hold any type and types are checked at runtime.
9. What is NaN?
Represents "Not-a-Number", usually from invalid math operations.
10. What is console.log() used for?
For debugging and printing values to the console.
Medium Questions (11–20)
11. Explain closures
A closure remembers variables from its outer scope even after the outer function finishes.
12. Higher-order functions
Functions that take another function as an argument or return one.
13. Difference between call(), apply(), bind()
-
call: calls function withthisand arguments separately -
apply: calls function withthisand arguments as array -
bind: returns new function with boundthis
14. Event loop
JavaScript is single-threaded. The event loop manages async callbacks.
15. Difference between for...in and for...of
-
for...in: iterates over keys -
for...of: iterates over values
16. Destructuring assignment
Unpacks arrays or objects into variables.
17. Spread operator
Expands iterable elements into individual elements.
18. Promises
Represent eventual completion/failure of async operations.
19. Async/Await
Simplifies working with promises.
20. Memoization
Caches function results to optimize performance.
Difficult Questions (21–30)
21. Currying
Converts a function with multiple arguments into nested single-argument functions.
22. Prototype vs __proto__
-
prototype: object assigned to a function for inheritance -
__proto__: actual object reference for an instance
23. new keyword
Creates a new object, sets prototype, binds this, returns object.
24. Shallow vs deep copy
-
Shallow: copies reference only
-
Deep: copies all nested objects
25. WeakMap & WeakSet
Objects are garbage-collected if no other reference exists.
26. Debouncing vs Throttling
-
Debounce: triggers function after delay of inactivity
-
Throttle: triggers function at intervals
27. Event delegation
Attaching a single event listener to a parent for child elements.
28. Generator functions
Functions that can pause execution using yield.
29. Proxy
Intercept fundamental operations on objects.
30. Memory leaks
Caused by closures, forgotten timers, detached DOM nodes.
✍️ By Ashish | 2025-10-21T09:01:53.478Z