preventDefault or stopPropagation?
preventDefault or stopPropagation — what does each do?
Answer out loud in under a minute: a definition, one concrete example, and one pitfall or trade-off.
Hints
Hint 1
Say what still happens after each: does the event keep propagating, does the default action still run?
Solution
Show the approach
Answer
preventDefault cancels the browser's default action, such as following a link or submitting a form, and the event still propagates. stopPropagation stops the event reaching further elements, and the default action still happens. stopImmediatePropagation also skips the remaining listeners on the same element.
Assistant
Sign in to use the assistant — ask what the problem means, get a hint when you're stuck, or have your current work reviewed. Conversations save to your account.