When working with promises in javaScript there will come a time now and then where I just want to return a resolved promise without having to bother with the promise constructor to do so. In addition there is also doing the same but with a rejected promise, just retuning that inside the body of a promise so that is just directly results in a catch statement being called.Well luckily even with native javaScript promises there is the Promise.resolve, and Promise.reject methods that can do just that.
These resolve and reject promise prototype methods will come in handy often when creating a long chain of promises. When making long promise chains I often just want to return a resolve or rejected promise inside the body of a then of catch method call in the chain. It is basically a more appropriate alternative to using the promise constructor, passing a function with a resolve argument, and then calling resolve inside the body of that function that is given to the promise constructor. This kind of solution will work, sure but why bother doing that when I have the Promise.resolve method.
So todays post will just be on the Promise.resolve, and promise.reject methods.
Read More