I have some code here...
async function test() {
for(let i = 0; i < 10000; i++){
console.log("test");
}
}
console.log("a");
test();
console.log("b");
Now my understanding is that test()
here should run asynchronously and if I would want to run a routine after it's completion I would use .then()
after it.
I'm not doing that here though so surely it should just do it's thing in the background while everything else contiunes running? With that understanding I would expect some output like this:
a
b
test
test
..etc
However what I actually get is this...
a
test
test
...etc
b
Why does this happen? It seems that console.log("b")
waits until test()
completes but that's synchronous behaviour.
Apologies if something similar has been asked before but I couldn't find anything on this myself.