Full answer
This puzzle measures microtask ticks with a chain that adds one step per tick.
Why return Promise.resolve('x') is slower:
- An async function's own promise is resolved with the return value. If the value is a thenable (a promise), the spec does not use it directly. It queues a job that calls promise.then(resolveOuter, rejectOuter) (tick 1). When the inner promise settles, the then callback runs and resolves the outer promise (tick 2). Only then can the outer promise's own handlers run (tick 3).
- That is about two extra ticks compared with returning a plain value.
Why return await is earlier:
- await of a native promise uses one tick. After it, the function returns a plain value, so the outer promise resolves right away, and its handler runs on the next tick.
Order from the output: tick 1, return await, tick 2, return promise, tick 3, tick 4.
Practical consequences:
- This almost never matters for correctness, but tests that assert on the exact order of logs can break when someone changes return to return await.
- return await has a real purpose inside try/catch. Without await the function returns before the promise settles, so a rejection escapes the catch block.
- Promise.resolve(p) returns p itself if p is a native promise, so wrapping does not add ticks.
- Any object with a then method is a thenable. await and resolve adopt it, and a thenable's then method gets called in a microtask job.
Do not write code that depends on tick counts. Know the rule so you can explain a surprising log order.
javascript
async function viaReturn() { return Promise.resolve('x'); }
async function viaAwait() { return await Promise.resolve('x'); }
const order = [];
viaReturn().then(() => order.push('return promise'));
viaAwait().then(() => order.push('return await'));
Promise.resolve().then(() => order.push('tick 1'))
.then(() => order.push('tick 2'))
.then(() => order.push('tick 3'))
.then(() => order.push('tick 4'));
setTimeout(() => console.log(order.join(' > ')), 0);The printed line shows the order in which the two async functions and the numbered ticks completed. Save it as app.js and run it with node app.js. Output (Node.js v24.22.1, same on two runs): tick 1 > return await > tick 2 > return promise > tick 3 > tick 4
Key points
- Returning a promise from an async function costs about two extra ticks.
- return await settles earlier but is needed for try/catch.
- Promise.resolve(p) returns p when p is a native promise.
- Never depend on exact tick counts in real code.
Common mistakes
- Claiming that all promise callbacks run in creation order.
- Removing return await inside a try block and losing the catch.
- Writing tests that depend on microtask tick counts.
- Forgetting that thenables are adopted through an extra job.
Follow-ups
- Why does return await matter inside try/catch?
- What does await do with a non-promise value?
- How would you prove the tick counts with a counter chain?
Tips
- Say 'adopting a thenable' to show depth.
- Give the practical point about try/catch.
- Admit that tick counts should not drive design.