0

im having troubles with how async calls within regular functions work. heres an example snippet of what im trying to do:

var x = foo();

function foo() {
    async function bar() {
    return y;
    }

var z = await bar();
console.log(z);

return z;
}

my question is do async calls within a function “out live” the actual function?

i noticed in this example foo() is getting called first and thus returning undefined, and then afterwards will it foo() print the correct value.

and what is the correct solution to getting the correct return value? thank you!

sweglord
  • 85
  • 5

0 Answers0