What's the difference between stopPropagation() and stopImmediatePropagation()?
element.addEventListener('click', e => {
e.stopPropagation();
e.stopImmediatePropagation();
});
While both methods prevent event propagation, they differ in scope: stopPropagation() prevents the event from bubbling up to parent elements but allows other event listeners on the same element to execute. stopImmediatePropagation() is more aggressive - it prevents both event bubbling AND stops other listeners on the same element from executing, even if they were attached before the current listener. This is particularly useful when you need to ensure no other handlers interfere with your event handling.