Well, i am new to javascript and heard it is single-threaded. In my mind if you make an asynchronous request, it should start an own thread which controls if the server already responded. This won’t work in Javascript. I am thinking is there some built-in mechanism which saves all listeners and calls them, depending on conditions they have “agreed” to (onreadystatechange).
This is just an assumption and I guess i am totally wrong. Well, maybe somebody can help me here?
Only the javascript execution itself is single-threaded, as explained here. Yet, the underlying engine might use more threads.
So, the HTTP request (created somewhere deep in the bowels of the browser) might have its own thread, but when something (like a response) happens, it will fire an event to be queued into the JS task scheduler. As soon as the current script execution has ended, the
onreadystatechangefunction will be called.