JavaScript_React_Interview_Questions-1 (1)
JavaScript_React_Interview_Questions-1 (1)
A: var: Function-scoped and can be redeclared. let: Block-scoped and cannot be redeclared. const:
A: A closure is a function that retains access to its parent scope even after the parent function has
closed. Example:
function outer() {
let count = 0;
return ++count;
};
counter(); // 1
A: The event loop continuously checks the call stack and the task queue. If the call stack is empty, it
async/await provides syntactic sugar to work with promises, making code more readable.
A: Hoisting is JavaScript's behavior of moving declarations to the top of the scope. var and function
declarations are hoisted, but let and const are not initialized.
Q: What are higher-order functions in JavaScript? Can you give an example?
Array.map, filter.
Q: What is the difference between `==` and `===`? Which one should be used and why?
A: `==` performs type coercion before comparison. `===` checks both value and type. `===` is
Q: Explain the difference between call, apply, and bind methods in JavaScript.
A: call: Invokes a function with a specific this and arguments. apply: Similar to call but takes
A: Prototypes are objects from which other objects inherit properties. Inheritance is implemented by
Q: What are the different types of errors in JavaScript? How would you handle them?
A: Types: SyntaxError, TypeError, ReferenceError, etc. Use try-catch blocks or the onerror event for
handling errors.
Q: What is the difference between functional components and class components in React?
A: Functional components are stateless and simpler, while class components can manage state and
lifecycle methods.
Q: What is the Virtual DOM in React, and how does it help in performance optimization?
A: The Virtual DOM is a lightweight copy of the real DOM. React uses it to minimize real DOM
Q: What are React Hooks? Explain the `useState` and `useEffect` hooks with examples.
A: Hooks enable functional components to use state and lifecycle features. Example: useState
manages state, useEffect handles side effects.
Q: How would you handle forms in React? Explain with an example of controlled vs.
uncontrolled components.
A: Controlled components use state to manage input values. Uncontrolled components use refs to
Q: What is the purpose of `key` props in lists? Why are unique keys important in React?
A: Keys help React identify which items changed, improving rendering performance. Unique keys