How it works
The explanation, with examples you can run.
Sequential or parallel
Press Run to see what your code prints, in order.
Runs in this browser, in an isolated frame with no access to this page. console.log, info, warn and error are shown; code runs as a classic script, so use an async function for await.
Awaiting in a loop has the same effect: for (const id of ids) await load(id) loads one at a time. That is right when each step needs the previous one, or when you must go easy on a server; otherwise map to promises first and await them together.
Errors
A rejected promise makes await throw, so ordinary try/catch works. One trap: inside try, write return await work() rather than return work(); without the await, the function returns before the promise settles and your catch never sees the failure.
Press Run to see what your code prints, in order.
Runs in this browser, in an isolated frame with no access to this page. console.log, info, warn and error are shown; code runs as a classic script, so use an async function for await.
In ES modules (and in Node's .mjs files) you can also use await at the top level, outside any function.
Check yourself
2 questions. Get them all right to finish this topic.
0 of 2 right so far. Get all two to finish this topic.