1/18
JAVASCRIPT
INTERVIEW
QUESTIONS
1. What is JavaScript?
JavaScript is a high-level, interpreted programming language
used to create interactive and dynamic web content. It is a
versatile, lightweight, and event-driven language that can run
on both the client and server sides.
2. What are the data types supported by JavaScript?
JavaScript supports the following data types:
Primitive Types: String, Number, BigInt, Boolean,
Undefined, Null, Symbol.
Non-Primitive Types: Object (including arrays, functions).
3. What is the difference between let, const, and var?
var: Function-scoped, allows redeclaration, hoisted with
undefined.
let: Block-scoped, no redeclaration, hoisted but not
initialized.
const: Block-scoped, no redeclaration, and must be
initialized during declaration.
4. Explain how == and === differ.
== checks for value equality with type coercion.
=== checks for strict equality without type coercion
5. What is a closure?
A closure is a function that retains access to its outer scope
variables even after the outer function has executed.
6. What is hoisting?
Hoisting is JavaScript's behavior of moving variable and
function declarations to the top of their scope during
compilation.
7. Explain the concept of this in JavaScript.
this refers to the context in which a function is executed. Its
value depends on how the function is called.
8. What are JavaScript prototypes?
Prototypes allow objects to inherit properties and methods
from other objects.
9. What is the difference between null and undefined?
null: A deliberate non-value.
undefined: A variable declared but not assigned a value.
10. How does JavaScript handle asynchronous operations?
JavaScript uses the event loop with callbacks, promises, and
async/await for asynchronous operations.
Example: Using a Callback
Example: Using a Promise
Example: Using async/await
11. What is a promise?
A promise represents the eventual completion or failure of
an asynchronous operation.
12. What are async/await functions?
async/await allows writing asynchronous code that looks
synchronous.
13. Explain event delegation in JavaScript.
Event delegation allows you to handle events for multiple
child elements at the parent level.
14. What are JavaScript modules?
Modules allow you to organize code into reusable files using
import and export
15. How can you prevent a function from being called
multiple times?
You can use a debounce function.
16. What is the event loop?
The event loop processes tasks from the queue and stack
for asynchronous operations.
17. What is the difference between apply() and call()
methods?
call(): Invokes a function with a specific this value and
arguments passed individually.
apply(): Similar to call(), but arguments are passed as an
array
18. What is bind() method used for?
The bind() method creates a new function with a specific
this value and optional arguments.
19. What is a JavaScript event loop?
The event loop continuously checks the call stack and the task
queue, executing tasks from the queue when the stack is
empty.
20. Explain the concept of "event bubbling" and
"event capturing".
Event Bubbling: Events propagate from the target element
to the parent elements.
Event Capturing: Events propagate from the parent
elements to the target element.
21. What is the difference between deep copy
and shallow copy?
Shallow Copy: Copies only the first layer of an object.
Deep Copy: Copies all layers of an object.
22. What are generator functions?
Generators are special functions that can pause execution
and resume later.
23. What is the new keyword used for?
The new keyword creates an instance of an object from a
constructor function.
24. How do JavaScript’s setTimeout and setInterval
work?
setTimeout: Executes a function after a specified delay.
setInterval: Repeats execution at specified intervals.
25. What is a WeakMap and how is it different from a
Map?
WeakMap: Keys are only objects and are garbage collected.
Map: Keys can be any type
26. What is a Set in JavaScript?
A Set is a collection of unique values.
27. What is Object.create() used for?
It creates a new object with a specified prototype.
28. How does JavaScript’s garbage collection work?
JavaScript uses a mark-and-sweep algorithm to identify and
remove unused objects.
29. What are "decorators" in JavaScript?
Decorators are functions that modify classes or methods.
They are experimental features.
30. Explain the difference between prototype and
__proto__.
prototype: An object associated with functions for
inheritance.
__proto__: A reference to the object's prototype.