DEV Community

Discussion on: If Javascript Is Single Threaded, How Is It Asynchronous?

sirius93 profile image
Nandan Kumar

Hey Eugene,
Would you please help me understand how does this happen. Any link or reference would be very helpful.

TIA :)

karataev profile image
Eugene Karataev

Well, it's a joke and shouldn't be used anywhere in production code.

We iterate on every element (N) in array of numbers and ask a JS engine to log this number in the console after N milliseconds from now. So, these numbers will be logged in a sorted way, because time in our universe flows in one direction 😁

Thread Thread
sirius93 profile image
Nandan Kumar • Edited on

Yes, indeed it's a joke and should not be used anywhere in production. But it's nice to know how things work, It took me some time to figure out but it was worth it.
Thanks 😁