JavaScript Q&A;
Q1: What are JavaScript’s key features?
A: Lightweight, interpreted, prototype-based, asynchronous support, first-class functions,
event-driven.
Q2: Difference between == and === in JavaScript?
A: '==' compares values with type coercion, '===' compares values and types (strict equality).
Q3: What is the difference between var, let, and const?
A: var – function scoped, can be redeclared; let – block scoped, reassignable; const – block
scoped, not reassignable.
Q4: What is a closure in JavaScript?
A: A function that retains access to variables from its outer scope, even after the outer function has
finished.
Q5: Explain event bubbling and capturing.
A: Bubbling – event propagates from child to parent; Capturing – event propagates from parent to
child.
Q6: What is the difference between null and undefined?
A: null – intentional empty value; undefined – variable declared but not assigned.
Q7: What are JavaScript promises?
A: Objects representing the eventual completion or failure of an async operation. States: pending,
fulfilled, rejected.
Q8: What is async/await?
A: Syntax sugar over promises, making async code look synchronous.
Q9: Difference between synchronous and asynchronous code?
A: Synchronous – executes line by line blocking code; Asynchronous – non-blocking, executes
callbacks/promises.
Q10: Write a JavaScript function to reverse a string.
A: function reverseStr(str) { return str.split('').reverse().join(''); } console.log(reverseStr('hello')); //
'olleh'