I have two functions a
and b
that are asynchronous, the former without await
and the later with await
. They both log some
As other answers say/indicate: an async function
just runs on spot until it encounters an await
- if there is no await
, it runs completely.
What may be worth adding that async
unconditionally makes your result a Promise
. So if you return something, there is a difference already and you simply can not get the result without returning to the JS engine first (similarly to event handling):
async function four(){
console.log(" I am four");
return 4;
}
console.log(1);
let result=four();
console.log(2,"It is not four:",result,"Is it a promise ?", result instanceof Promise);
result.then(function(x){console.log(x,"(from then)");});
console.log(3);