Facebook Pixel

Do Web APIs run on the main thread in JavaScript?

The operations run outside the engine (on browser threads or the OS). Only the callbacks run on the main thread (call stack). This is why async operations do not block the UI the heavy work happens outside, and only the short callback runs on the main thread.

Verify This Answer

Cross-check this information using these trusted sources:

More FAQs in Web APIs in JavaScript Explained

Functions provided by the browser (or Node.js) that run outside the JS engine. Examples: setTimeout, fetch, DOM methods, localStorage, geolocation. They handle async operations and push callbacks to queues when done.

No. They are provided by the browser (or Node.js runtime). The JS engine only knows JavaScript. Web APIs are the host environment's extension to the language. This is why they are not available in a bare JS engine without a host.

You call a Web API (like setTimeout). The Web API runs the operation outside the engine. The engine continues. When the operation completes, the Web API pushes the callback to the microtask or macrotask queue. The event loop moves it to the stack when it is empty.

Still have questions?

Browse all our FAQs or reach out to our support team

Want to upskill yourself?

Our courses are taking a Coffee break, but your curiosity shouldn't. Stay engaged with namastedev linkedin, youtube, discord and other resources while you wait.

0
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.
Please Login.