Javascript Flashcards
7 cards from real React practice questions. Tap to flip, then mark Knew It or Still Learning โ missed cards come back until you master them.
Read the first 7 Javascript flashcards as text
What does the useState hook return?
Answer: An array with the state value and a setter function
useState returns a pair: the current state and a function to update it.
Which hook lets you perform side effects in a function component?
Answer: useEffect
useEffect handles side effects such as data fetching and subscriptions.
When does an effect with an empty dependency array `[]` run?
Answer: Only once after the initial mount
An empty dependency array runs the effect only once after the first render.
What is the purpose of the cleanup function returned by useEffect?
Answer: To run before the component unmounts or before re-running the effect
The returned function cleans up subscriptions or timers before unmount or re-run.
Which hook returns a mutable object whose `.current` persists across renders without causing re-renders?
Answer: useRef
useRef returns a mutable ref object that persists without triggering re-renders.
What rule governs where Hooks can be called?
Answer: Only at the top level of a component or custom hook
Hooks must be called at the top level, not inside loops, conditions, or nested functions.
Which hook is preferred for managing complex state logic with multiple sub-values?
Answer: useReducer
useReducer suits complex state transitions handled through a reducer function.
Written and edited by Nathan Beja, founder of Practice Test Geeks, with AI assistance. We have not yet matched this exam's facts to an official source, so confirm fees, dates and rules with the exam body. Editorial policy