For example, you read your user settings from local storage (that’s a callback!). Based on those settings, you make a request from some external server with a database connection, (that’s callback #2). Before you render that information on the screen, you retrieve something else from the database (that’s callback #3).
These steps are very common when you build a large enterprise app. In your code, there will be a callback function, written in a callback function, that’s in another callback function. You can imagine if these functions are spread over separate files that you’d have a hard time reading this code back a month later.
A Promise typically has one of these 4 states.
- fulfilled – when the promise succeeds
- rejected – when the promise failed
- pending – ongoing, hasn’t been fulfilled or rejected yet
- settled – it has been fulfilled or rejected already