1.

What are promises in JavaScript?

Answer»

A promise in JavaScript represents the eventual completion or failure of an asynchronous operation and its resulting value. It is a PROXY for a value that might not necessarily be known when the promise object is CREATED. Promises are used in Asynchronous methods, where instead of immediately returning a value, the method returns a promise to provide a value at some POINT in the future. To put it simply, promises are a way to return synchronous values from an asynchronous method. The value for which the promise acts as a proxy, can either be a resolved value, or a reason that it was rejected.

A promise can be in either of the three states:

  1. Pending: This is the INITIAL state of a promise, i.e. it has neither been fulfilled nor been rejected.  
  2. Fulfilled: This state means that the operation was completed successfully.
  3. Rejected: This state means that the operation could not be completed successfully.

A promise is considered to be SETTLED if it is either in the fulfilled state or in the rejected state.



Discussion

No Comment Found