Skip to main content
← JavaScript Lesson 3 / 5

Promises & Async

A promise is an IOU for a value that isn't ready yet. It starts pending, then settles once — either fulfilled with a value or rejected with an error. .then runs on success; .catch runs on failure. async/await is the same thing written in a straight line.

Build the chain

.then adds +1 on the success path; .catch only fires after a reject.

Settle it (happens once)

Run the chain

Settle the promise first — a pending IOU has nothing to run yet.

State

pending

Chain

value (pending…)

No handlers yet — add a .then or .catch.

Current value

Same thing with async/await

// Promise chain
const p = Promise.resolve(1);
p.then(x => x + 1)      //  ← .then transforms the value
 .catch(err => "recovered"); //  ← .catch handles an error

// Same thing with async/await
try {
  const v = await p;    //  ← await  ===  .then
  return v + 1;
} catch (err) {         //  ← catch  ===  .catch
  return "recovered";
}

await p is .then; try/catch is .catch. Same machinery, straighter line.