Event Prevent Default
Predict Output Easy
Question
What does this code print?
Code
function App() {
const h = (e) => { e.preventDefault(); console.log("handled"); };
return <form onSubmit={h}><button type="submit">Go</button></form>;
}
// Submit form — what logs?
Hint
preventDefault stops the form submission; handler still runs.
Explanation
preventDefault() stops the default form submission behavior (page reload). The handler continues and logs "handled". The form does not reload the page.
Related Resources
Related Lessons
- Event Handling
Learn events.
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.