Can anyone please explain why the result of the below code is - 1,2,3,4,5,6
?
Does this imply that normal code within the promise body executes synchronously? I was under the impression that the result of the promise depends on how it is handled by the .then()
block, i.e., the promise body code is executed asynchronously.
console.log(1);
const promise = new Promise((resolve) => {
console.log(2)
resolve()
console.log(3)
});
console.log(4)
promise.then(() => {
console.log(5)
}).then(() => {
console.log(6)
})