Promises are used to handle async operations in JavaScript. Promises are nothing you can assume it to be an empty object or some data in it. Promises give us the guarantee that it will call the callback function whenever there is data in the promise object. JavaScript guarantees that a promise will be called only once whether it’s a failure or success. There are majorly four promise APIs –
Promise.all() => If you have to make parallel API calls it will wait for all of them to finish and get the result. As soon as any of the APIs in Promise.all rejected it will throw an error. It will not wait for others to complete.
Promise.allSettled() => If we make parallel API calls it will be the same as the promise.all but if any of them are rejected it will wait for all the promises to be settled. Irrespective of failure or success it will give you all results.
Promise.race() => In this the API which finishes first will be the winner. Basically it will give you the value of first settled promise. And if first promise gets rejected it will throw error.
Promise.any() => It also takes list of promises and it is very much similar to promise.race but in this it will wait for first fullfilled/successful promise. If all the promises in list will be failed then the result will be an Aggregate Error (Error of all the three errors).