Promise in Javascript
Promise in Javascript
JavaScript: The
Future of Async
@ritika-pethkar
What is a Promise?
A Promise is an object that represents
the eventual success or failure of an
async operation.
It’s a placeholder for a future value that
hasn’t arrived yet.
@ritika-pethkar
Promise States
A Promise has 3 states:
Pending – Initial state
Fulfilled – Operation successful
Rejected – Operation failed
As soon as the promise resolves, .then() or
.catch() is triggered automatically.
@ritika-pethkar
How Promises
Work ?
Instead of passing callbacks, you return a
Promise and chain actions like:
Promises are:
Immutable once resolved
Chained with .then(), .catch(), .finally()
@ritika-pethkar
Anatomy of a
Promise Object
Prototype – Methods: .then(), .catch(),
.finally()
PromiseState – pending | fulfilled |
rejected
PromiseResult – Holds the result or error
(default: undefined)
@ritika-pethkar
Callback vs Promise
– Code Comparison
Callback :-
@ritika-pethkar
Callback vs Promise –
Feature Comparison
@ritika-pethkar
Why Promises
Matter?
✨ Promises solve real problems in async JS:
Cleaner code
Better error handling
Improved control over flow
🧠 Mastering Promises prepares you for
async/await!
@ritika-pethkar