Promises Terms in JavaScript
- Promise Chaining
- Instead of calling the second .then() inside the handler for the first .then(), we can return the promise returned by json(), and call the second .then() on that return value.
- Catching errors in Promise:
- To support error handling, Promise objects provides a .catch()method.
- It is very simple to remember: when asynchronous operation succeeds, .then() is called whereas when it fails, the handler is passed to .catch().
- If we add .catch()to the end of a promise chain, then it will be called when any one of the .then() method fails in the chain.
- States of promise:
- pending: the promise has been created and the function has neither succeeded nor failed.
- fulfilled: the asynchronous function has succeeded. When a promise is fulfilled, its .then() handler is called.
- rejected: the asynchronous function has failed. When a promise is rejected, its .catch() handler is called.
- settled: to cover both fulfilled and rejected states.
- resolved: if its settled
Comments
Post a Comment