The result of an
async
function will be a
Promise
. You either need to
await
it, or use the continuation to read the result.
You should also avoid calling the function twice. Call it once and store the result in a variable.
async function TrueOrFalsFn(){
function firstFunction(){
return new Promise((resolve, reject) => {
let y = 100
setTimeout(() => resolve(y + 1), 2000)
});
}
async function secondFunction(){
let result2 = await firstFunction();
return result2 === 101;
}
let output = await secondFunction();
if (output) {
alert("Yes");
}
else {
alert("No");
}
return output;
}
NB: The calling code will also need to
await
the result of this function, or use the continuation to read the result.