const c = async() => console.log("2")
const a = async() => {
console.log("1")
await c()
console.log("4")
}
const b = () => console.log("3");
console.log("start")
a();
b();
I would expect the sequence here to be 3 1 4 2, but apparently it is not. Async function seem to execute synchronously and be added to the callstack UNTIL they return, and that is when the rest is added to the event queue. Why is that and why is it not instantly added to the event queue?
Link to ECMA spec & other reads also greatly appreciated
This seem to explain why 1 is printed first, but not why the 2 is printed second, since by that answer it should return a promise on the FIRST await, but it actually executes b synchronously: When does async function actually return a pending promise?