useState Initial
Predict Output Beginner
Question
What does this code print?
Code
function App() {
const [n, setN] = useState(5);
return <p>{n}</p>;
}
// What renders?
Hint
useState(5) initializes state to 5.
Explanation
useState(5) sets the initial state to 5. On first render, n is 5, so the paragraph shows 5.
Related Resources
Related Lessons
- State
Learn state.
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.