Prepare for the Salesforce JavaScript Developer Exam. Utilize comprehensive quizzes, flashcards, and multiple choice questions with hints and explanations. Boost your exam readiness!

Practice this question and more.


When is an async function typically resolved?

  1. Immediately upon declaration

  2. After all synchronous code completes

  3. After being called

  4. When all promises are resolved

The correct answer is: After being called

An async function is typically resolved after being called. This means that once the function is invoked, JavaScript will begin to execute it. If the async function contains asynchronous code, such as a Promise, the resolution of the async function will depend on the completion of that Promise. As a result, while the async function itself is initiated upon being called, its completion or resolution may occur later, based on the asynchronous operations inside it. The timing of resolution relative to other code execution is essential. Although it can seem that it resolves immediately, execution of the async function is queued in the event loop, allowing other synchronous code to execute first. Therefore, understanding that an async function starts running when it is called is crucial, while the actual resolution may happen later, aligned with the handling of any promises it returns.