Well I'm new in javascript, and confused about what's the async in javascript and the communication between event loop?
1 Answers
When you load a page, you are effectively sending a request to the server. The server responds and the page is displayed in your browser. However, you might need further communication with the server for your page.
If you do not want to reload the page each time when you send a request, then you need to send a request through Javascript. This is how it works:
- the browser sends the request to the server
- the server handles the request
- the server sends back a response
- the browser receives the response and handles it
There are two ways of doing it. The browser can wait for the response or the browser can set up a handler for the event when a response is received from the server. If the browser waits, then it is a sync request, since the browser is synchronizing. If you have a so-called callback at the browser, which is executed when a response from the server is received, then it is an async request.
Sync request:
- browser sends a request to the server
- browser waits for response
- when the response arrives or is timed out, the script in the browser continues
Async request:
- browser sends a request to the server
- browser continues to run the script
- when the response arrives, the callback function is triggered
It is recommended to use async request, since in that case, the script at the browser continues to run.

- 64,414
- 37
- 100
- 175