0

Can anyone explain why we can make asynchronous call in Javascript, meanwhile it is a single-threaded language.

It looks like synchronous/asynchronous has nothing to do with single/multi-threaded.

A good place to study this topic would be very helpful too!

Note: this question only concerns about Javascript running in browser. Javascript running in the server side, such as Node.js could be a very different topic.

David Liu
  • 16,374
  • 12
  • 37
  • 38
  • @forgivenson `setTimeout` and `setInterval` are asynchronous client side and has nothing to do with sending a callback to the server... [This blog entry helped me understand it](http://ejohn.org/blog/how-javascript-timers-work/) – Benjamin Trent Sep 29 '14 at 19:10
  • @forgivenson the question is not about "what is asynchronous calling", it is about how the asynchronous calling is implemented under the hood. – David Liu Sep 29 '14 at 20:19
  • It's just context switching. It's not 100% busy all of the time. – Wolph Sep 29 '14 at 20:22
  • Finally, I got an answer, please watch this great video:http://vimeo.com/96425312. Basically, Javascript itself is single-threaded, but browser isn't. All the asynchronous calls are handle separately by browser's Web APIs. – David Liu Sep 30 '14 at 15:49

0 Answers0