1

I am interested in understanding better the following statement from the Mozilla documentation:

A very interesting property of the event loop model is that JavaScript, unlike a lot of other languages, never blocks. Handling I/O is typically performed via events and callbacks, so when the application is waiting for an IndexedDB query to return or an XHR request to return, it can still process other things like user input.

If JavaScript is single threaded, how does it process in parallel?

Mark
  • 90,562
  • 7
  • 108
  • 148
marzann
  • 19
  • 2
  • 3
    Where does it say that it processes anything in parallel? – Thomas Jul 21 '18 at 18:37
  • @Thomas It does a _lot_ of processing in parallel actually, just not user-supplied JavaScript code (but native code implementing many of the web-standards). – John Weisz Jul 21 '18 at 18:38
  • *parallel* is not the same concept as *asynchronous*. – trincot Jul 21 '18 at 18:42
  • @trincot You can have numerous HTTP requests running, while you are reading a `File` object into an `ArrayBuffer`, while you are doing a set of transactions on an IndexedDB instance, etc.. That's quite parallel! You just don't do the parallel stuff yourself (usually), you merely use it. – John Weisz Jul 21 '18 at 18:45
  • @JohnWeisz, and your point is? I was just stating that these are two different concepts. – trincot Jul 21 '18 at 18:48
  • 1
    I appreciate the link to Node.js explanation. Now I understand better how asynchronous requests can be processed in a highly concurrent, but not parallel, way. The idea that "everything runs in parallel except your code" was also helpful, as your discussion above. Thank you! – marzann Jul 21 '18 at 19:17

0 Answers0