loading...

re: JS illustrated: The event loop 🔁 VIEW POST

TOP OF THREAD FULL DISCUSSION
re: Great article, but one question how’s this asynchronous ?
 

Thanks @amineamami !
According to MDN: Asynchronous , asynchronous code may refer to multiple related tasks happening without waiting for each other to complete.

In our case, if the code was not asynchronous, the setTimeout call whould have blocked the execution of the program until it was completed printing "Two" at the console.

But this is not the case. The program continues executing, printing "three" and, after that, the callback of the setTimeout is called, printing "Two" at the end.

 

Hmm, it seemed to me just like synchronous execution with a bit of instructions reordering.

Thats right! Javascript language itself does not have any asynchrony built in.
The environment (browser, node etc) is the one that arranges the events resulting in asynchronous execution (the use o callbacks, promises, ajax calls etc)

code of conduct - report abuse