Basic Flow of How Web Services Operate
Components of a Web Browser
- Call Stack: A stack that holds functions to be executed sequentially in JavaScript.
- Web API: APIs provided by the web browser for performing
asynchronous tasks
, such as AJAX and setTimeout. - Task Queue: Also known as the Callback Queue, it stores callback functions passed from the Web API.
- Event Loop: Checks if the Call Stack is empty; if it is, it moves tasks from the Task Queue to the Call Stack.
setTimeout(() => console.log("Async Hi hun"));
console.log("Hello! World");
// Hello! World
// Async Hi hun
Even though asynchronous code is executed first, we can see it printed later.
2 minutes to read