0

We can make Fetch or any other Async request with JavaScript, But Java script is itself a single threaded quite confusing

  • 2
    ECMAScript is single threaded, however the host environment (e.g. JavaScript) can provide additional asynchronous functionality like XMLHttpRequest and [*Fetch*](https://developer.mozilla.org/en-US/docs/Web/API/Fetch_API). – RobG Feb 19 '18 at 06:09

5 Answers5

2

You're confusing asynchronous programming with multi threaded programming. See this answer: Does async programming mean multi-threading?

izengod
  • 1,116
  • 5
  • 17
  • 41
2

Javascript runs on a core which is single threaded and its also a event driven language that make all request into events, application running in node js runs asynchronously using node event loop and event loop where looks upon the events and process them asynchronously.

So the request you make taken by events and processed asynchronously.

Pankaj Bhardwaj
  • 2,081
  • 1
  • 17
  • 37
1

The trick is that the browser / nodejs instance has other threads for network handling, file reading etc. So it actually is multithreaded, but you dont need to deal with that as js opens these threads for you in the background. You just work with promises and callbacks to get the results out of these threads.

Jonas Wilms
  • 132,000
  • 20
  • 149
  • 151
0

Browser eventLoop:

https://developer.mozilla.org/en-US/docs/Web/JavaScript/EventLoop

A very interesting property of the event loop model is that JavaScript, unlike a lot of other languages, never blocks. 

Chetan Raikwal
  • 138
  • 1
  • 1
  • 9
-1

Refer this content - receiving-results-asynchronously

M Pankaj Arun
  • 84
  • 1
  • 8