r/learnjavascript • • May 01 '20

Async vs. Sync

Post image
413 Upvotes

81 comments sorted by

View all comments

38

u/NoStranger6 May 01 '20

Except that’s not necessarly true for javascript.

JavaScript is not multi-threaded. So if your task 1 a for loop that last 20 seconds, tasks 2-3-4 are not ran concurently.

So really what happens is that each function calls are queued one after another and the execution of the response of async functions are only added when the promise is completed or the callback is called.

Which allows the program to keep executing other functions while it “waits” for the async function.

And this is why I love NodeJs for a server. It is very easy to write async code in JavaScript.

3

u/PierreAndreis May 01 '20

this should be up in this thread