Promise vs Async/Await

In this blog, we will dive into the comparison between Promise and async/await in Javascript. While both are used to deal with asynchronous operations, but there are some differences about their syntax and characteristics. Let's start!!!


 1. Promise

- State: promise has 3 states
+ Pending: initial state, neither resolved nor rejected, before the operation completes
+ Resolved: Operation completes successfully
+ Rejected: Operation fails

- Methods: promise has 3 methods
+ then(): executes when the Promise is resolved
+ catch(): executes when the Promise is rejected
+ finally(): executes regardless of the Promise's outcome 
Ex:

2. Async/await

- async function returns a Promise
- await can only be used inside an async function. The await keyword pauses the execution of the async function until the Promise  is resolved or rejected
- Should use async/await inside try/catch to handle error
Ex: 


3. Comparison

- Syntax


- When to use


4. Reference

Geeksforgeeks. (2025, April 4). Difference between Promise and Async/Await in Node. 

Post a Comment

0 Comments