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 COOKIE POLICY
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.
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, […]
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 […]
The Bloated SaaS Era: Paying More for Less While Businesses Wait
SaaS was supposed to make business faster, smarter, and more efficient. Instead, it’s become bloated, expensive, and painfully slow to change. The platforms we rely on—Salesforce, Workday, SAP, and others—haven’t truly innovated in years. Yet, they demand massive investments in re-implementation, process re-engineering, and data migration just to keep up. It’s time to ask: Are […]
Reid Braswell Joins UDig as Vice President, Software Engineering
UDig is proud to welcome Reid Braswell as our new Vice President of Software Engineering. With over 13 years of experience in technology consulting, Reid brings deep expertise in digital transformation, modern software engineering, and client-focused solutions. His leadership and passion for solving complex challenges make him an exceptional addition to the UDig team. Reid’s […]
Energy 2025 – Expansion of Fossil Fuels or Carbon Reduction?
Now that the election is behind us, we have an opportunity to anticipate the possible effects on the energy industry under this new administration. What strategies will be impacted? What will remain the same? What opportunities can we take advantage of in 2025? This blog is meant to dig into these questions and provide some […]