Loading topic
setTimeout schedules work for later, and how to run a script in Node.js or a browser console. The examples use new Promise(...) in its simplest form.7 min readsetTimeout with a callback. It also builds on the previous chapter: a promise starts pending and settles once, as either fulfilled with a value or rejected with a reason. Here you l6 min readnew Promise((resolve, reject) => ...). The examples attach handlers with .then and .catch. You only need to know that .then(fn) runs fn with the fulfillment value and `.catch(5 min readthen, catch and finally. It explains what each handler receives, when it runs, and wha5 min readnew Promise or Promise.resolve, and how to attach then, catch and finally handlers to it. You should also be comfortable with arrow functions, including the difference between an expression body (x) => x + 1 and a block b5 min readthen, catch and finally attach handlers, and how a value returned from then becomes the input of the next step. Here we follow the other path: what happens when something goes wrong. You will see how a rejection moves down a c5 min readnew Promise, chain them with then and catch, and follow how a rejection moves down a chain to the nearest catch. The examples use plain then chains. The next chapter shows the same patterns with async/await.5 min readthen, catch and finally, and that you know how a rejection skips forward through a chain to the next catch. You should also be able to run JavaScript in Node.js or a browser console. Everything here builds on those ideas. async5 min readnew Promise, attach handlers with then, catch and finally, and write simple async functions. You should also know that setTimeout schedules a callback for later. The question here is when "later" happens. Promise handlers are always async5 min readFileReader or the onload event on images all work this way. To use them in a promise chain or with await, you need a small adapter that turns "call me back5 min readthen, catch and finally build chains, how errors travel through a chain, and how async/await works with try/catch. It also helps to know that promise callbacks run as microtasks, which the previous chapters covered.5 min readthen chains, and the microtask queue covered in earlier chapters. It explains a behavior you have already relied on without seeing it: when you resolve a promise with another promise, or return a promise from then, the outer 6 min readcatch, the combinators (Promise.all and the rest) and async/await work. It covers the mistakes that show up most often in real promise code. Each one runs without a syntax error, so it is easy to miss. For each mistake you will see the symp5 min read