What’s happening here?? the order of execution is commented.
dad()
is async and returns a promise. shouldn’t it be executed after console.log('faster')
?
two()
is async w/o await
and still it’s executes before console.log(5)
g()
is awaited and executes as the last one?!
async function dad(){
async function g(){
return new Promise((a,b)=>{
setTimeout(() => {
console.log('im waiting') //4th
}, 2000)
a(6)
})
}
async function two(){
console.log(2) //1st
}
two()
await g()
console.log(5) //3rd
}
dad()
console.log('faster') //2nd