The Promise at a later time either gets fulfilled (successful), also known as resolved in JS terminology or gets failed, also known as rejected in JS terminology.
Let us understand it with an example. Below function returns a Promise.
Now Promises have some methods attached to them which are useful when you want to run a block of code (callback function) when Promise either gets resolved or rejected. In code we would write something like this:
Although you can have a catch at an intermediate position, one should keep it at last because it will show all the rejections at one same place, if there are more than one.
If you liked this post, please consider sharing it with your network and subscribe to the newsletter below.