The difference between “fulfill” and “resolve” a Promise

The difference between “fulfill” and “resolve” a Promise

When we are working with Promises in Javascript, there are two terms commonly confused: fulfill and resolve.

According to the dictionary:

  • Fulfill: Bring to completion or reality; achieve or realize (something desired, promised, or predicted).
  • Resolve: Settle or find a solution to (a problem, dispute, or contentious matter).

That’s everything we need to solve all the mess around these terms that we tend to use indistinctly.

Let’s take the next code snippet as an example:

const anotherPromise = //

const promise = new Promise((resolve, reject) => {
 setTimeout(() => {
 }, 2000) 

According to the definition of Promise, the method resolve can receive either a value or a thenable object (an object with a method called then,which is commonly another Promise) and that parameter will be passed to the subsequent thencalls.

The key part of that is either a value or a thenablewhich means that the next call tothencan receive that specific value or whatever thethenableobject returns (even a failed state).

Worth noting that the “thenable” object mentioned before, can be resolving another “thenable” object itself, and so on. There is where the word “resolve” makes its magic. It’s resolving a chain of “thenable” objects in order to get a value at the end.

On the other hand, fulfillment makes reference to the stage when we get a value after that chain of “resolves” that takes place before we are able to get into the “then” callback.

We hope this small article helps you understand a bit more about these terms and, as usual, if you have something to share or have any questions, please let us know in the comments below. We’ll be happy to help.

. . .

Regos Dev Studio is a product development company that builds add-ons for Jira and Confluence, combined with the development of custom solutions in a variety of languages.

Don’t forget to check out our website, visit our Atlassian marketplace listing. You can also follow us on Twitter or LinkedIn and stay tuned for updates!

Leave a Reply

Your email address will not be published. Required fields are marked *