JavaScript Interview Prep Summary
6. JavaScript Interview Questions with Answers
1. What is JavaScript?
JavaScript is a high-level, interpreted programming language used to create interactive effects within web
browsers.
2. Difference between var, let, and const?
- var: function-scoped, hoisted, can be re-declared and updated.
- let: block-scoped, not hoisted like var, can be updated but not re-declared in the same scope.
- const: block-scoped, cannot be updated or re-declared.
3. What is hoisting?
Hoisting is JavaScript's behavior of moving declarations (variables and functions) to the top of their scope
before execution.
4. What is a closure?
A closure is a function that has access to its own scope, the outer function's scope, and the global scope
even after the outer function has returned.
5. Difference between == and ===?
- == checks for value equality after type coercion.
- === checks for both value and type equality.
6. What is a Promise?
A Promise is an object representing the eventual completion or failure of an asynchronous operation.
7. What is async/await?
async/await is syntax to handle promises more cleanly. `await` pauses execution until the promise resolves,
and `async` marks the function as asynchronous.
JavaScript Interview Prep Summary
8. What is the DOM?
The DOM (Document Object Model) represents the structure of a webpage as a tree of objects, allowing
JavaScript to interact with and manipulate the content and structure.
9. Difference between map, filter, forEach?
- map: transforms each item and returns a new array.
- filter: filters items based on a condition and returns a new array.
- forEach: executes a function for each element but does not return anything.
10. What is event delegation?
Event delegation is a technique where a single event listener is added to a parent element to manage events
for its child elements using event bubbling.
11. What is the difference between null and undefined?
- null: intentional absence of value.
- undefined: variable declared but not assigned any value.
12. What are arrow functions and how are they different?
Arrow functions provide a shorter syntax and do not bind their own `this`, `arguments`, or `super`.
13. How do you clone an object?
Using spread operator: const newObj = { ...oldObj };
14. What is destructuring?
Extracting values from objects or arrays and assigning them to variables.
15. What is the spread operator?
The spread operator (`...`) allows an iterable to be expanded into individual elements.
16. What is event bubbling?
Event bubbling is the process where the event starts from the deepest element and propagates upward
JavaScript Interview Prep Summary
through its ancestors.
17. What is lexical scope?
Lexical scope refers to the ability of a function to access variables from the parent scope in which it was
defined.
18. What is a callback function?
A function passed into another function as an argument, which is then invoked inside the outer function.
19. What is the difference between shallow copy and deep copy?
- Shallow copy copies only the first level.
- Deep copy duplicates nested structures too.
20. What is debouncing?
Debouncing limits the rate at which a function is executed. It waits a certain amount of time before running
again.