AceDevHub
Advanced JavaScript Interview QuestionsAdvancedCode Output

JavaScript · Question 87

Does await always yield, even when the awaited value is not a pending Promise?

Direct answer

Yes: evaluating await suspends the async function and its continuation resumes asynchronously through Promise-related job scheduling, even when the value is a plain value or an already-fulfilled Promise.

await-yields.js
async function f() {
  console.log("A");
  await 123;
  console.log("B");
}

console.log("C");
f();
console.log("D");
Output
C
A
D
B

Consider async function f(){ console.log("A"); await 123; console.log("B"); } console.log("C"); f(); console.log("D");. The output starts C, A, D, and B appears later when the async function continuation runs.

A plain value supplied to await is treated through the Promise-resolution machinery. The async function does not simply continue synchronously because the value is already available. This property gives await a consistent suspension boundary.

  • Do not use await casually in hot loops when no asynchronous dependency exists; every suspension changes scheduling and can add overhead.
  • An already-fulfilled Promise still resumes through asynchronous job processing rather than inline continuation.
  • This is why inserting or removing an await can change observable ordering with surrounding Promise callbacks.