[go: up one dir, main page]

0% found this document useful (0 votes)
5 views8 pages

Promise in Javascript

A Promise in JavaScript is an object that represents the eventual success or failure of an asynchronous operation, with three states: pending, fulfilled, and rejected. Promises allow for cleaner code, better error handling, and improved control over asynchronous flow compared to callbacks. Understanding Promises is essential for mastering async/await in JavaScript.

Uploaded by

Shahwali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views8 pages

Promise in Javascript

A Promise in JavaScript is an object that represents the eventual success or failure of an asynchronous operation, with three states: pending, fulfilled, and rejected. Promises allow for cleaner code, better error handling, and improved control over asynchronous flow compared to callbacks. Understanding Promises is essential for mastering async/await in JavaScript.

Uploaded by

Shahwali
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

Promises in

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 :-

With promises, you


stay in control — no

Promise :- more Inversion of


Control!

@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

You might also like