A Promise is a Javascript object that takes in a function, called the executor. The executor itself takes in two parameters, resolve
and reject
, that are themselves functions. Inside the promise, resolve
must be invoked with the sucessful returned value of the promise instance. You can also invoke the reject
function with the reason for the promise instance's failure, although doing so is optional.
Promises are used to capture the values of asynchronous functions. They resolve only once the asynchronous function has returned.