JavaScript Interview Questions and Answers
Basic JavaScript Questions
1. What is JavaScript?
JavaScript is a high-level, interpreted programming language used to create dynamic and interactive
web pages.
2. Difference between var, let, and const
var - function scoped, can be redeclared and reassigned.
let - block scoped, cannot be redeclared.
const - block scoped, cannot be redeclared or reassigned.
3. Data Types in JavaScript
Primitive: String, Number, Boolean, Undefined, Null, Symbol, BigInt
Non-Primitive: Object, Array, Function
4. == vs ===
== checks only value, === checks value and type.
5. Closure
A function that remembers variables from its outer scope.
6. Hoisting
JavaScript moves declarations to the top of the scope.
7. null vs undefined
undefined - declared but not assigned.
null - explicitly set to "no value".
8. Template Literals
Use backticks (`) to embed variables: `Hello ${name}`.
9. typeof operator
Returns the data type of a variable.
10. Arrow Functions
Short syntax: const add = (a, b) => a + b;
Intermediate JavaScript Questions
11. call(), apply(), bind()
call() - calls function with arguments.
apply() - same, but args in array.
bind() - returns new function.
12. Event Loop
Handles asynchronous operations between call stack and callback queue.
13. Promises
Object representing future completion/failure of async operation.
14. async/await
Simplifies promises for cleaner async code.
15. Higher-order Functions
Functions that take/return another function.
16. Destructuring
Extract values easily: const {name, age} = person;
17. Spread & Rest Operators
Spread: expands [...arr]; Rest: collects (...args).
18. Sync vs Async
Synchronous blocks code; asynchronous doesn't.
19. Event Bubbling & Capturing
Bubbling: child -> parent. Capturing: parent -> child.
20. Shallow vs Deep Copy
Shallow: top-level only. Deep: full copy (e.g., [Link]([Link](obj))).
Advanced JavaScript Questions
21. this keyword
Refers to the object that invokes the function.
22. Prototypal Inheritance
Objects inherit from another via prototype chain.
23. Callback Function
Function passed and executed later.
24. Memoization
Caching results to improve performance.
25. Debouncing & Throttling
Debounce - delay function after inactivity.
Throttle - limits function execution rate.
Bonus Topics
- JavaScript Modules
- localStorage vs sessionStorage vs cookies
- Deep equality vs Object equality
- [Link] vs Browser JavaScript