All VideosJavaScript Tutorials

What is Promise in JavaScript| JavaScript Tutorials in Hindi | Interview Question #43

In JavaScript, a promise is an object representing the eventual completion or failure of an asynchronous operation. It allows you to handle asynchronous operations more easily and effectively by providing a cleaner syntax than traditional callback-based approaches.

A promise can be in one of three states:

  1. Pending: Initial state, neither fulfilled nor rejected.
  2. Fulfilled: The operation completed successfully.
  3. Rejected: The operation failed.

Promises have methods to handle these states:

  • then(): This method is used to specify what to do when a promise is fulfilled or rejected.

Promises are commonly used for asynchronous operations such as fetching data from a server, reading files, or making network requests. They provide a more readable and maintainable way to work with asynchronous code compared to nested callbacks.

Leave a Reply

Your email address will not be published. Required fields are marked *

error: Content is protected !!