Loading topic
await are built on Promises. If you understand how a Promise changes state, you can predict what await will do. This chapter covers how Promises are created, the three states they can be in, and the rules that6 min readnew Promise((resolve, reject) => ...). It also assumes you are comfortable with arrow functions and basic try/catch. Here you will learn how then, catch, 6 min readthen, catch, and finally, and read a short promise chain. You should also be comfortable with arrow functions, object methods, and classes. The await operator gets its own chapter next. Here, the focus is on the outside of an6 min read.then() chains work. You also know that an async function always returns a Promise. Here we look at the other half of the pair: the await operator. It pauses 5 min readtry/catch/finally works in synchronous JavaScript, what a rejected Promise is, how .catch() works on a Promise chain, and what await does to an async function. Here you will see how those pieces fit together: a rejection becomes an exception at the `aw6 min readPromise.all, `Promis5 min readawait, with try/catch in async functions, and with Promise.all and Promise.allSettled from the previous chapters. You should also be able to run scripts in Node.js 16 or later. In Node.js 16+, performance.now() is available globally, which the 6 min readawait, handle errors with try/catch/finally, and run several operations together with Promise.all. Each mistake below follows the same pattern: the code looks right, runs without a syntax error, and quietly does the wrong thing. For each 5 min readawait does: it pauses the async function until a Promise settles, and the rest of the program keeps running. This chapter explains how that works. You will see where the paused code waits, when it runs again, and why await continuations always run before a `setTim6 min readawait only worked inside an async function. Top-level await removes that limit for one kind of file, the ES module. In an ES module you can write await directly in the module body, outside any function. This chapter covers where top-level await works, what it does to m6 min readawait, and handle failures with try/catch/finally. One gap remains. Once a Promise exists, nothing in the Promise API lets you stop the work behind it. A slow request keeps running after the user has left the page. A search6 min read