Why this code can not printout anything?
The expected result should be async result is: 2
. But it is 0.
"use strict"
// run consoleLogPromise
consoleLogPromise( PromiseAChangeCount() );
// a utility which will always console log any promise
async function consoleLogPromise(callback) {
//const res = await callback(); TypeError: callback is not a function
const res = await callback;
console.log("async result is: ", res);
}
// a promise returning function
async function PromiseAChangeCount() {
let count = 0;
await setTimeout(() => {
count = 2
}, 200);
return count;
}