React Multiple Choice Questions (MCQs)
1. Core React
Q1. What is JSX?
- A) A syntax extension for JavaScript
- B) A new programming language
- C) A type of HTML
- D) A React component
Answer: A. JSX is a syntax extension for JavaScript that allows you to write HTML-like structures in the same file as JavaScript code.
Q2. Which hook is used to manage state in functional components?
- A)
useEffect - B)
useState - C)
useContext - D)
useReducer
Answer: B. useState is the primary hook used for adding state to functional components.
2. Component Lifecycle & Hooks
Q3. Which hook is analogous to componentDidMount and componentDidUpdate?
- A)
useState - B)
useEffect - C)
useMemo - D)
useCallback
Answer: B. useEffect lets you perform side effects in functional components, effectively replacing lifecycle methods like componentDidMount, componentDidUpdate, and componentWillUnmount.
Q4. What is the purpose of the key prop when rendering lists?
- A) To style the elements
- B) To provide a unique ID for React's virtual DOM diffing algorithm
- C) To bind data to the element
- D) None of the above
Answer: B. Keys help React identify which items have changed, are added, or are removed, which optimizes re-rendering performance.
3. State Management
Q5. In React, data flows in which direction?
- A) Bottom to top
- B) Bi-directional
- C) Top to bottom (Unidirectional)
- D) Randomly
Answer: C. React enforces a unidirectional data flow (top to bottom), meaning data is passed down from parent components to child components via props.