Host tasks and ECMAScript jobs
How it works
ECMAScript defines jobs, including promise reactions, and delegates scheduling to host hooks. HTML event loops process tasks from task queues and perform microtask checkpoints; timers and user interactions are examples of host task sources. There is not one universal JavaScript task queue. Node uses a different event-loop organization, while both hosts integrate promise jobs. Do not infer a total order for unrelated task sources.
Example 1
setTimeout(() => console.log("timer"), 0);Promise.resolve().then(() => console.log("reaction"));console.log("script");Expected output in the tested environment:
scriptreactiontimerIn this Node example the reaction is processed before the later timer callback.
Example 2
Save each file separately. Serve with a local HTTP server and open index.html. This is a multi-file example, not a single editor snippet.
index.html
<!doctype html><meta charset="utf-8"><title>Tasks</title><script> setTimeout(()=>console.log("timer"),0);Promise.resolve().then(()=>console.log("reaction"));console.log("script");</script>Expected output in the tested environment:
scriptreactiontimerThe browser’s microtask checkpoint processes the promise reaction before the timer task.
Common mistake
Task and microtask are host scheduling terms; do not call every asynchronous operation a separate ECMAScript thread.
Practice
Label the synchronous code, promise reaction and timer callback in both fixtures; explain what the host, rather than the language, supplies.
Run this practice in the documented local environment. ByteMind module and asynchronous grader support is not yet verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Host tasks and ECMAScript jobs — Knowledge Check
Reason about the concept and predict its behavior in the indicated environment.
Which standard defines the browser event loop and task model?
Which term describes the specification work scheduled for a promise reaction?
Can the relative order of unrelated browser task sources always be derived from a single FIFO queue?
For Host tasks and ECMAScript jobs, what is the console output of example 1 in Node.js 22.16.0?
setTimeout(() => console.log("timer"), 0);Promise.resolve().then(() => console.log("reaction"));console.log("script");For Host tasks and ECMAScript jobs, what is the console output of example 2 in the browser fixture?
// File: index.html<!doctype html><meta charset="utf-8"><title>Tasks</title><script>setTimeout(()=>console.log("timer"),0);Promise.resolve().then(()=>console.log("reaction"));console.log("script");</script>