For Chrome :
In a browser, the V8 engine is responsible for executing JavaScript code, while the Blink engine manages rendering tasks like processing HTML and CSS, and offering Web APIs. When JavaScript code running in V8 accesses a Web API, it communicates with Blink, which carries out the requested operation. Blink and V8 collaborate closely within the browser environment — V8 focuses on JavaScript execution, and Blink provides the APIs and rendering functionalities the JavaScript code can use.
Detailed Version-
V8 is a JavaScript engine that comprehends only ECMAScript (core JavaScript).
It lacks any browser-specific features like setTimeout(), fetch(), or DOM APIs. The browser contains Web APIs (like timers, DOM, geolocation) implemented in native code (i.e. C++).
When the browser starts executing a webpage, it performs two crucial tasks. It sets up a global object (window in browsers) and attaches Web API functions to that object as properties long before the JavaScript is executed.
When a piece of JavaScript code makes a call to a Web API function, V8 notices that the function you called is on the global object.
V8 then forwards the task to the C++ implementation of the browser through internal bindings. V8 doesn’t know about Web APIs, it is only interested in JS.
The browser detects tasks to run like timers, HTTP requests, or DOM manipulations outside the V8 engine. When the Web API finishes its job (like a timer finishes), it puts a call-back in the Task Queue.
The Event Loop is looking at two things: the Call-Stack (to see if it is empty) and the Task Queue to see if there is any work to be done. If the Call Stack is empty, the Event Loop will take the first thing on the queue and add it to the Call Stack, where V8 can run it.
Node.js has a C++ internal library called libuv which implements Asynchronous I/O with its own thread pool, but the pattern is the same: V8 runs the JS, libuv handles the async tasks, and passes the event to the Event Loop to run the callback as soon as the Call Stack is empty.