Menu

Post image 1
Post image 2
Post image 3
Post image 4
Post image 5
Post image 6
1 / 6
0

Promise in javascript

DEV Community·Abinaya V·26 days ago
#UdLJB25r
Reading 0:00
15s threshold

Abinaya V

A Promise in JavaScript is an object that represents the result of an asynchronous operation.

It helps handle tasks like:

  • API calls

  • File loading

  • Database requests

  • Timers (setTimeout)

Instead of waiting for the task to finish, JavaScript continues running other code.

Promise States

A Promise has 3 states:

Enter fullscreen mode Exit fullscreen mode

  • Pending → Initial state

  • Resolved / Fulfilled → Operation successful

  • Rejected → Operation failed

Promise Methods

Method and Purpose

.then() -> Runs when promise is successful

.catch() -> Runs when promise fails

.finally() -> Runs always

output

Callback Hell.

output

Read More