1.

What is Promise and explain its states?

Answer»

Callback functions are functions that can be passed to another function as ARGUMENTS and executed there to complete a routine or action. Those functions depend on ONE another, so it could get quite messy with so many callback functions nested in so many layers. This is what is referred to as callback hell.

As an alternative to callbacks in JavaScript, promises are USED to handle asynchronous operations. In addition to handling MULTIPLE asynchronous operations, they provide better error handling than callbacks. Promises can be a better way for a user to read the code effectively and efficiently, especially when that particular code performs multiple asynchronous operations. The Promise object represents the result of an asynchronous operation (or its failure) and the resulting value. The promise is in one of the following STATES:

  • Pending: In its initial state, neither fulfilled nor rejected.
  • Fulfilled: Indicating that the operation was successful.
  • Rejected: Indicating that the operation failed.


Discussion

No Comment Found