Caffeinated Coder
Book an appointment
Lesson 19 · Async JavaScript

Callbacks and promises

A callback is a function you hand to other code to call later; a promise is an object that stands for a value that is not ready yet. Follow ten real lines that wrap setTimeout in a promise and chain two .then calls: the script prints start and end at once, and half a second later the promise is fulfilled, its saved callbacks pass through the microtask queue, and the console prints got 1000.

12 min11 steps5 questionsIntermediate
Fig 19 · Interactive
Loading figure…
or ← →

Quiz Unlocks after the last step.