Predict State After Updates
Predict Output Medium
Question
What is the value of `count` after this code runs?
Code
const [count, setCount] = useState(0);
setCount(5);
setCount(prev => prev + 3);
setCount(prev => prev * 2);
// What is count?
Hint
Process each update in order: 0 → 5 → 8 → 16.
Explanation
Starting at 0: setCount(5) sets it to 5. prev => prev + 3 makes it 5 + 3 = 8. prev => prev * 2 makes it 8 * 2 = 16. The final value is 16.
Related Resources
Related Lessons
Look up unfamiliar terms
A beginner-friendly glossary explains jargon in plain English — variables, functions, DOM, Promise, and more.
Decode error messages
Plain-English explanations of common errors — what they mean, why they happen, and how to fix them.
Build real projects
Apply what you learned by building guided projects with starter code and solutions.