1. Guard the await
Wrapping awaits in try/catch lets you handle a rejected promise as a thrown error.
try {Typorithm · medium
Step 1 of 8 · intro card
Async & Event Loop
Awaiting a rejected promise throws, so wrap awaits in try/catch. Sequential awaits run one-after-another and are slow, while awaiting Promise.all runs them in parallel. An unhandled rejection propagates out of the async function as a rejected promise.
An await on a rejected promise throws at that line, exactly like a synchronous throw, so you guard it with a surrounding try/catch and the catch block receives the rejection reason.
Writing await a(); await b(); runs the calls sequentially — b only starts after a finishes — which is slow when they are independent; awaiting Promise.all([a(), b()]) instead kicks both off together and waits for both in parallel.
If you do not catch a rejection, it does not vanish: the async function itself returns a rejected promise, so the error propagates to that promise's caller and, if still unhandled, becomes an unhandledrejection.
await on a rejection throws — wrap awaits in try/catch.
Sequential awaits are slow; await Promise.all runs in parallel.
An uncaught rejection makes the async function return a rejected promise.
try {
const data = await fetchUser(); // await rethrows a rejection
} catch (err) {
console.error(err); // caught here
}
const [a, b] = await Promise.all([taskA(), taskB()]); // parallelConnect each part of the code to the concept before you type.
Wrapping awaits in try/catch lets you handle a rejected promise as a thrown error.
try {Awaiting a rejected promise throws synchronously at that point, so it lands in the surrounding catch.
const data = await fetchUser(); // await rethrows a rejectionThe catch block receives the rejection reason exactly as if it were a thrown exception.
} catch (err) {Inside catch you can log, recover, or rethrow; the rejection is now a normal caught error.
console.error(err); // caught hereAwaiting Promise.all starts both tasks at once and waits together, unlike sequential awaits which run one after another.
const [a, b] = await Promise.all([taskA(), taskB()]); // parallelRead the concept map and follow the code breakdown.
Type the implementation, repair mistakes and work through every recall exercise.
Use the final check without hints; revisit weak concepts in short practice sessions.