I'm trying to understand the order of execution of javascript asynchronous code in the event loop.
Here's my very short code snippet.
How can we explain the actual order of execution: in promise
-> end
-> in then
? Why does the promise constructor run before the console.log('end')
?
const p = new Promise((res, rej) => {
console.log('in promise')
res()
})
p.then(() => console.log('in then'))
console.log('end')