Are Promises Still Used with the Introduction of async/await?
async/await
has significantly simplified the usage of promises and allows us to write asynchronous code that looks like synchronous code.
When using async
and await
, much of the complexity of promises (and sometimes even their very presence!) disappears.
So are promises still in use?
Under the hood, async/await
still relies on promises. When you use await
within an async
function, it awaits the resolution of a promise and then returns the resolved value. If the promise is rejected, it throws an error that can be caught using a try/catch
block.
In essence, async/await
builds upon promises. To truly master async/await
, it is essential to have a solid understanding of promises.
Also, promises are used directly when more fine-grained control or composition of asynchronous operations is required.
For example, let’s say you have three asynchronous calls you need to make. Two of them A
and B
are independent, and the last C
cannot be executed until the both have finished.
You can just use await and execute them serially:
await A; await B; await C;
Or you could use Promises:
await Promise.all([A, B]); await C;
I've developed a guide called Master JavaScript Promises. It's a beginner-friendly guide with one goal: to help you build your intuition of how Promises works, so that you can work with async functions confidently.
I have created a set of resources for learning asynchronous JavaScript. These guides—Callbacks, Promises, and Async/Await —cover everything I’ve learned from years of real-world JavaScript experience.
If you found this article helpful, you’ll get so much out of these guides. Each one is optimized for those “lightbulb moments,” building a strong mental model for how asynchronous JavaScript works and how you can use it to create fast, dynamic applications.