I am new to learn javascript; I encountered a big confusion when I was learning async await.
async function async1() {
console.log("async1 start");
await async2();
console.log("async1 end"); // why will this task be placed in microtask?
}
async function async2() {
console.log("async2");
}
async1();
console.log("script end");
I don't understand why will "console.log("async1 end")" be placed in microtask? in my opinion, the "console" should be a synchronized task rather than an asynchronous task.
async-awaitis syntactic sugar forPromise(fn).then(res, rej), the code part afterawaitis just the same asrescallback passed tothen.async2finishes. Which doesn't make any sense considering you've saidawaitfor it. Also, were it true, consider thatawaitwould be completely useless construct to keep code in linelet x = await p(); console.log(p)would never log anything useful then.