I encountered a problem while attempting to test a Promise within an event listener. Although everything seems to be working fine, the execution order is not as expected.
var test = document.querySelector('#test');
test.addEventListener('click',function(){
Promise.resolve().then(function(){
throw 'first';
}).catch(function(er){
console.log(er);
});
});
test.addEventListener('click',function(){
console.log('second');
});
test.click();
<div id="test"></div>
Can someone explain why the second listener is finishing before the first listener?