JS DOM: list of non-blocking functions
List of non-blocking functions
in js, in browser, what functions are non-blocking. don't include node.js
(ai answer)
In browser JavaScript, non-blocking means async operations that don't freeze the main thread (they hand work to the browser/event loop and return immediately). Synchronous code (loops, heavy calculations, most array methods, JSON.parse, DOM reads/writes, etc.) does block.
Main categories of non-blocking APIs
- Timers:
setTimeout,setInterval,requestAnimationFrame,queueMicrotask - Network:
fetch(),XMLHttpRequest(async mode), WebSocket,navigator.sendBeacon - Promises / async: Any
Promise,async/awaitfunctions,Promise.all/race/etc. - Events:
addEventListener,dispatchEvent, MutationObserver, ResizeObserver, IntersectionObserver - Storage / data: IndexedDB, Cache API, localStorage/sessionStorage (reads are sync, but many wrappers/async variants exist), FileReader, streams (
ReadableStream,WritableStream) - Media / sensors: Geolocation, MediaDevices, Web Audio API scheduling, many WebGL/WebGPU async parts
- Workers:
Worker,SharedWorker,ServiceWorker(offload to other threads entirely) - Other Web APIs:
Notification, Payment Request, Web Crypto (subtlemethods),requestIdleCallback, most modern APIs that return Promises
Quick rules of thumb
- If a function returns a Promise or takes a callback and is documented as async → non-blocking.
- If it does heavy work and runs to completion before returning → blocking (move it to a Worker or break it into chunks with
setTimeout/requestIdleCallback). - DOM and most core language features are synchronous/blocking by default.
Example of non-blocking:
setTimeout(() => console.log("later"), 0); // doesn't block fetch("/api").then(r => r.json()); // doesn't block
Example of blocking:
for (let i = 0; i < 1e9; i++) {} // freezes the UI
That's the core picture for browser JS (no Node).