This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Promise.resolve('1').then(console.log); | |
document.addEventListener('testEvent', () => console.log('2')); | |
document.dispatchEvent(new Event('testEvent')); | |
console.log('3') | |
Promise.resolve('4').then(console.log); | |
// Related question at StackOverflow | |
// https://stackoverflow.com/questions/71324258/the-callback-function-of-addeventlistener-is-queued-in-macro-task-queue-in-event | |
// EXPLANATION: dispatchEvent invokes event handlers SYNCHRONOUSLY! |