In this code, callback function of .then
is executed before the console.log("still going on...")
but normally callback function of .then
shall be posted to micro stack first before coming to call stack.
What is happening differently here and why?
async function test(){
console.log("start");
console.log("going on...");
await new Promise((resolve, reject) => {setTimeout(() => resolve("promise value"), 5000);})
.then((result) => console.log(result))
.catch((error) => console.log(error));
console.log("still going on...");
}
test();
console.log("end.");
Output:
start
going on...
end.
promise value
still going on...