Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 142353

Javascript: Do not wait for async function [duplicate]

$
0
0

Consider the following code snippet:

async function f() {
    console.log("entering");
    for (let i=0;i<=1e9;i++) {}
    console.log("quitting");
}

async function g() {
    console.log("before");
    f();
    console.log("after");
}

g();

I would expect the function g() to call f()without waiting for it to finish. Thus, I would expect the output to be

before
entering
after
quitting

However, g() actually waits for f() to finish. Why does this happen, when f() is supposed to be an async function?


Viewing all articles
Browse latest Browse all 142353

Trending Articles