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

async / await · sugar for promises

PromissaVSRace Condition Rex
Promissa saysasync/await is syntactic sugar that makes promise-based code read synchronously.

Mark a function async and use await before a promise to pause until it settles, getting the value directly. An async function always returns a promise. This turns .then chains into straight-line code — far easier to read and reason about, especially with loops and conditionals.

Power-ups you unlock

Race Condition Rex attacks — common mistakes

Boss battleRewrite a .then chain as an async function with await.

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>const wait=(ms,v)=>new Promise(r=>setTimeout(()=>r(v),ms));
(async()=>{ const a=await wait(300,'A'); const b=await wait(300,'B'); document.getElementById('o').textContent=a+b; })();</script></body></html>
▶ Open the interactive comic issue
‹ Promises · All · AllSettled · Race · AnyError Handling · Try / Catch Around Await ›