JavaScript Interview Questions & Answers
Q: What are var, let, and const?
A: `var` is function-scoped, `let` and `const` are block-scoped. `let` can be reassigned, `const`
cannot.
Q: What is Hoisting?
A: JavaScript moves variable and function declarations to the top of their scope before execution.
Q: Difference between == and ===?
A: `==` compares value only; `===` compares value and type.
Q: What is Closure?
A: A closure is when a function remembers variables from its outer scope even after that scope
has ended.
Q: What is Promise?
A: An object representing the eventual completion or failure of an async operation.
Q: What is async/await?
A: Syntax to handle promises in a cleaner, synchronous-looking way.
Q: What is the Fetch API?
A: Used to make HTTP requests and handle responses using Promises.
Q: What are Arrow Functions?
A: Short syntax for functions: `const sum = (a,b) => a+b;`
Q: What is Destructuring?
A: Extract values from arrays or objects easily: `const {name, age} = user;`
Q: What is Event Bubbling?
A: An event propagates from the inner element to the outer elements in the DOM tree.
Q: What is a Higher Order Function?
A: A function that takes another function as an argument or returns one.
Q: What is NaN?
A: Represents 'Not a Number' but its type is 'number'.
Q: What is the Event Loop?
A: Handles asynchronous operations by moving tasks between call stack and callback queue.
Q: Difference between null and undefined?
A: `undefined` means variable declared but not assigned; `null` means intentional empty value.
Q: What is the difference between synchronous and asynchronous JS?
A: Synchronous executes line-by-line; asynchronous uses callbacks/promises for non-blocking
tasks.