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

  • Software Engineering

    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 […]

  • Software Engineering

    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 […]

  • Software Engineering

    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 […]

  • Software Engineering

    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, […]

  • Software Engineering

    Choosing the Right Modernization Approach

    When organizations decide it’s time to modernize their technology infrastructure, choosing the right approach is crucial. Modernization isn’t merely a technical upgrade; it’s a strategic business move that significantly impacts growth, agility, and long-term success. Here’s how your company can effectively begin to select the best modernization strategy tailored to your goals and challenges. In […]

  • Software Engineering

    TAG Panel: Differentiate Your Customer Experience

    Join the CX and Product Management Societies to hear from our panel of Human-Centered Design experts on the business value of Agentic AI.