If you put cursor in the first input, then click the button, you get one message.
If you put the cursor in the second one (with the
setTimeout), you get both messages.
Why doesn’t the ‘button was clicked’ message display in the first scenario?
Conversely, what is it about the
setTimeout that makes the second one show both alerts?
What you think is happening, is not really happening.
Try it with
console.log (which does not block) rather than
alert (which does block) and you’ll see that both event handlers do run. Hooray, one more reason to despise