HardEvent Loop & Promises💻 Output Question

async try/catch catches awaited rejection

💡

Hint

await unwraps Promise rejections into thrown errors. try/catch works naturally with async/await.

What does this output?

async function failingTask() {
  throw new Error('task failed');
}
async function main() {
  try {
    await failingTask();
    console.log('success');
  } catch (e) {
    console.log('caught: ' + e.message);
  }
}
main();

Correct Output

caught: task failed

Why this output?

Explanation: async functions wrap throws in rejected Promises. await converts rejection back to a thrown error that try/catch handles.

Key Insight: await unwraps Promise rejections into thrown errors. try/catch works naturally with async/await.

More Event Loop & Promises Output Questions

EasySynchronous code runs before setTimeoutMediumPromise microtask before setTimeout macrotaskMediumPromise chain passes valuesHardTwo Promise chains interleave in microtask queue

Practice predicting output live →

66 output questions with instant feedback

💻 Try Output Quiz