LESSON 13 / 16·2 min readIntermediate

Asynchronous JavaScript

Try code in the playground
01 Understand02 Recall03 Prepare

Understand the concept

Asynchronous JavaScript lets a program start work that may finish later without waiting synchronously for the result. A promise represents eventual completion, and async/await provides a readable way to work with promises. The runtime queues continuations and runs them when the current synchronous work has finished and the relevant checkpoints are reached.

Important ideas

  • Synchronous code runs first; queued promise callbacks run after the current code finishes.

  • await pauses that async function, not the whole JavaScript thread.

  • Making a CPU-heavy function async does not stop it from blocking.

  • An async function always returns a promise, including when it returns a plain value.

  • Use try/catch around an awaited operation to handle a rejection; synchronous try/catch cannot catch an unrelated later callback error.

  • The executor passed to new Promise(...) runs immediately; .then(...) callbacks run asynchronously.

Comparison:

PointPromise with .thenasync / await
What it providesA future result and callbacksSyntax for consuming promises
Error handling.catch(...)try/catch around await
Creates a new threadNoNo
Best readabilityShort chainsMulti-step flows

Work through the example

JavaScript
async function getTotal() {
  const price = await Promise.resolve(100);
  return price + 20;
}
getTotal().then(console.log); // 120
PAUSE & RECALL

Can you explain it without the notes?

How does async JavaScript run?

Use your own words. Explain an example and one limitation before checking the explanation.

Check your explanation

Asynchronous JavaScript lets a program start work that may finish later without waiting synchronously for the result. A promise represents eventual completion, and async/await provides a readable way to work with promises. The runtime queues continuations and runs them when the current synchronous work has finished and the relevant checkpoints are reached.

CONNECT IT TO YOUR INTERVIEW

Turn this concept into a clear answer.

  • Promises coordinate results; they do not create a new JavaScript thread or automatically make heavy work non-blocking.
Practice this concept
YOUR NEXT STEP

Keep connecting the ideas.

Next lesson: Working with promises

Adapted from 01_JAVASCRIPT_TYPESCRIPT.md · “How does async JavaScript run?”. Examples are study fragments; framework behavior can depend on your version.