Grokking Advanced JavaScript
0% completed
Introduction to Promises
The callback version of the online shop example had a problem that grew with every step. To load a user and then the user's orders, each step had to be written inside the callback of the step before it, every level checked for an error again, and the code trusted getUser to call the callback exactly once. All three costs come from the same design: the caller gives its code to the asynchronous function and waits to be called.
A promise reverses that design. Instead of accepting a callback, the asynchronous function returns an object immediately
.....
.....
.....
Like the course? Get enrolled and start learning!
Reading Progress
0%