Here's the code:
function B() {
return 'B';
}
async function test(b) {
await console.log('Z')
await console.log(b())
console.log('X')
await console.log("hihihi")
}
console.log('A');
test(B);
console.log('C');
console.log('P');
This output's to A Z C P B X hihihi
Question is:
- Why does the control goes to the caller function(that called the async function) after executing the first await statement? How's it useful?
- What's to be done to force execute all await statements one after the other somehow preventing it from going to the caller function?