Your Privacy

This site uses cookies to enhance your browsing experience and deliver personalized content. By continuing to use this site, you consent to our use of cookies.
COOKIE POLICY

Skip to main content

Promises In JavaScript Made Simple

Promises In JavaScript Made Simple
Back to insights

The simplest explanation of a ‘Promise’ in JavaScript can be referenced to a promise in real life. When creating a new promise, the promise constructor takes 2 arguments ‘resolve’ and ‘reject.’  Resolve means fulfilling the promises set forth. In other words, completing what you said you’re going to do. Reject means promise is not fulfilled, in other words not completing what was set forth. The code below shows how easy it is to create a new promise.

When the promise is executed we will get back a result. If the promise is successful it will return a ‘resolve,’ then we can utilize the Promise.then() function.

In the code below, we can pass in an argument, ‘fromResolve,’ to the Promise.then() function. This argument will show us the status of the resolve.

If the promise is not fulfilled we can then catch the result in a function called Promise.catch().

The code above showed that we chain the Promise.catch() after the Promise.then() and pass in an argument of ‘fromReject.’

Nested Promises

Let me add more complexity, in the code below I’ve created 3 different promises. We can then nest the promises together based on different rules and get the desired result.

Let say you don’t want to nest the promises and you don’t want to wait for one to finish and the second to start. We then can use the Promise.all() method to accomplish this objective and once they are all done it returns a result.

Promise Race

Another use case would be if you’re trying to pull the same data from three different servers. You could use the Promise.race() method to accomplish this. Below is the code example.

Conclusion

Now, you know what a promise is and how to create one in JavaScript. Give it a try! I hope this gave you a better and more simple understanding of Promises in JavaScript.

Digging In

  • Digital Products

    Building a Consultant in the Trenches: How Playing Offensive Line Shaped My Consulting Career

    People often ask me the same question when they find out that I played college football: “Do you miss it?” On the surface, it’s a bad question with an obvious answer. Yes. However, if I give myself a minute to sit with that question, the answer is more nuanced. Yes, I miss playing football, but […]

  • Digital Products

    Modernization That Sticks: Why Adoption, Not Just Architecture, Drives Success

    Modernizing a legacy sales platform in a large enterprise isn’t just a technical challenge, it’s a cultural and operational one. On a recent project with a Fortune 500 organization, several past attempts to replace the aging ERP system failed. Why? Because those efforts treated modernization as a software delivery exercise, not an adoption journey. When […]

  • Digital Products

    What to Ask in a UX Discovery Session

    Better questions lead to better design. In my years as a UI/UX designer, I’ve learned that many design challenges may come from misalignment at the start. Discovery sessions are where product clarity is either made or missed. These are a few discovery questions I consistently return to in the discovery phase of my UX design […]

  • Digital Products

    Designing For Play and Friction in a Fast-Paced World

    At UDig, play is an integral part of our philosophy. “Having fun” is embedded in our culture, and we always find opportunities to use play to encourage collaboration, ignite creativity, and make room for bold experimentation to build stronger teams and solve problems ranging from the seemingly simple to the most complex. I always have […]

  • Digital Products

    Config 2025 Day Two Recap

    It felt as though Config 2025 ended as soon as it began, and I believe those of us that attended are all the better for it. By the end of the day, various inspirational and informative talks had been given by thought leaders and innovators in the product space. Between sessions, we had the opportunity […]

  • Digital Products

    Inside Config 2025: What’s New in Figma

    Config 2025 kicked off with a bang on Day 1. Figma’s annual conference brings together designers, developers, and all those involved in the making of a product. The 2-day event has a stacked lineup of accomplished speakers ready to share their insights on the world of product building. At today’s opening keynote, the Figma team, […]