1. Home
  2. Interview Questions
  3. JavaScript
  4. What does an async function return, and how does await pause…

Try answering first

In a real interview nobody shows you the answer. Think it through (or type it), then reveal the answers and rate yourself.

1 Answer

0 0
InterviewQuestions Team ✔ Expert answer ✔ Best answer ·

Short answer: An async function always returns a Promise: a returned value resolves it and a thrown error rejects it. await pauses only that async function until the awaited promise settles, and the main thread keeps running. The rest of the function then resumes later as a microtask.

Detailed explanation

Marking a function async changes two things. First, its return value is always wrapped in a Promise. If you write return 42, the caller receives a Promise that resolves to 42. If the function throws, the caller receives a rejected Promise instead of a synchronous exception. Second, you can use await inside it.

When the engine hits await somePromise, it does the following:

  • If the value is not a promise, it is wrapped as if by Promise.resolve(value). You can await plain values and thenables, not just promises.
  • The async function is suspended at that point. Its local variables and position are saved.
  • Control returns to whoever called the function. That caller has already received the pending Promise.
  • When the awaited promise settles, the rest of the function is queued as a microtask. It resumes once the current synchronous code finishes and the call stack is empty.
  • If the awaited promise rejects, await throws that rejection reason at that line. This is why try/catch works with async/await.

The key point is that await does not block the JavaScript thread. Other code, event handlers, timers and rendering continue to run. Only the async function itself waits. This is very different from a blocking sleep in languages like Java or C.

Another detail interviewers like to probe: code before the first await runs synchronously, as soon as the function is called. An async function with no await at all runs fully synchronously. It still returns a Promise.

Example

console.log('1');

async function demo() {
  console.log('2');      // runs synchronously
  await null;            // suspends demo, queues the rest as a microtask
  console.log('4');
  return 'done';
}

const result = demo();
console.log('3');

console.log(result instanceof Promise); // true
result.then(value => console.log(value)); // 'done'

// Output order: 1, 2, 3, true, 4, done

The console.log('3') runs before '4'. Calling demo() returns immediately once it reaches await. The continuation only runs after the current synchronous script finishes.

Error handling follows the same model:

async function load() {
  throw new Error('Network failed');
}

load().catch(err => console.log(err.message)); // 'Network failed'

async function main() {
  try {
    await load();
  } catch (err) {
    console.log('Caught:', err.message);
  }
}

Common mistakes

  • Treating the result as the actual value. Writing const user = getUser(); console.log(user.name) gives undefined, because user is a Promise. You must await it or use .then().
  • Believing await freezes the whole program. It suspends only the current async function. Other code keeps running, which can cause race conditions if shared state changes in between.
  • Using await at the top level of a regular script. Top-level await works only in ES modules, and in Node.js only in ES module files (.mjs or "type": "module"). In CommonJS or classic scripts it is a syntax error.
  • Expecting a try/catch around the call to catch async errors. try { load(); } catch {} without await catches nothing. The rejection happens later, on the returned Promise.

Follow-up questions

  • What is the difference between return promise and return await promise inside a try/catch block?
  • Why does a .then() callback run before a setTimeout(fn, 0) callback?
  • Can you use await inside a regular (non-async) callback such as array.map?

Interview tip: Explain await in terms of the event loop: the function suspends, the caller gets a pending Promise, and the continuation runs as a microtask. Interviewers listen for exactly that sequence.

Reviewed by the Interview Questions editorial team · Last updated

How well did you know this?

Rate yourself to track progress, build your streak and get “didn't know” questions in your revision list.

Your Answer

More easy JavaScript questions

All easy questions →

Related Questions

Q1 of 10 · JavaScript
Next ›

Interview Questions

Free interview questions and answers, MCQ practice, online tests, mock interviews and group discussions — everything you need to crack your next interview.
📍 Dasardot LLC
1309 Coffeen Avenue STE 1200
Sheridan, Wyoming 82801
USA