Within an Immediately Invoked Function Expression (IFFE), I am returning a Promise. The first thing that is logged is first
, followed by third
, and then second
. Despite having the setTimeout inside the then
block, shouldn't everything within it be executed synchronously?
(() => {
return new Promise(resolve => {
console.log("first")
resolve()
})
.then(() => {
setTimeout(() => console.log("second"), 3000)
})
})()
.then(() => console.log("third"))