Dev HelpersOpen library
← Back

Schedule a microtask after synchronous work

Schedule a microtask after synchronous work in JavaScript.

Open this example in the interactive library

Source code

const steps = [];
queueMicrotask(() => steps.push("microtask"));
steps.push("synchronous");
await Promise.resolve();
console.log(steps);

Sample output

[ 'synchronous', 'microtask' ]