freecoding.school100% FREE · NO SIGNUP
Await StationISSUE #4 of 26

promises · then · catch · finally

PromissaVSRace Condition Rex
Promissa saysConsume promises with .then (success), .catch (error), and .finally (cleanup).

promise.then(onFulfilled) runs on success and returns a new promise, so .then calls chain. .catch(onError) handles any rejection in the chain above it; .finally(fn) runs either way. Returning a value (or promise) from a .then passes it down the chain — that's how you sequence async steps cleanly.

Power-ups you unlock

Race Condition Rex attacks — common mistakes

Boss battleChain two .then steps and a .catch on a resolving promise.

Example code

<!doctype html><html><head><meta charset="utf-8"></head>
<body style="background:#06040d;color:#e6e0ff;font-family:monospace;padding:20px"><pre id="o"></pre>
<script>Promise.resolve(2).then(n=>n*3).then(n=>document.getElementById('o').textContent='result '+n).catch(e=>console.error(e));</script></body></html>
▶ Open the interactive comic issue
‹ Promises · Pending · Fulfilled · RejectedPromises · All · AllSettled · Race · Any ›