Browsers are single threaded and this single thread (The UI thread) is shared between the rendering engine and the js engine.
- Therefore, if the thing you want to do takes a lot of time, it could halt the rendering (flow and paint).
- In browsers there also exists "The bucket" where all events are first put in wait for the UI thread to be done with whatever it´s doing. As soon as the thread is done it looks in the bucket and picks the task first in line.
setTimeoutyou create a new task in the bucket after the delay and let the thread deal with it as soon as it´s available for more work.
- the request is probably for JSON, rather than HTML, as is the traditional response data format for HTTP requests from a browser.