Promise static methods: .any, .all, .allSettled, .race and APIs: .then, .catch, .finally.
Here’s a lightning-quick refresher on promise static methods (.any, .all, .race, .allSettled, .resolve, .reject) and promise APIs (.then, .catch, .finally). Promise Static Methods Promise Static Methods are called on the Promise class itself, not on a promise instance. They help manage multiple promises. 1. Promise.any Takes an array of promises as input and returns a single promise. It will resolve if any of the promises in an array are resolved with the resolved value. If all the promises are rejected, promise will be rejected with the error “AggregateError: All promises were rejected”. Promise.any([Promise.reject('Error!'), Promise.resolve('Success!')]) .then(console.log) // 'Success!' .catch(console.error); 2. Promise.all This method takes an array of promises as input and returns a single promise. It resolves when all of the promises in the array have resolved, or rejects when any one of the promises rejects. Promise.all([Promise.resolve('First'), Promise.resolve('Second')]) .then(console.log) // ['First', 'Second'] .catch(console.error); 3. Promise.race This method takes an array of promises as input and returns a single promise. It will return the promise as soon as any of the promises is settled(either resolved or rejected). Promise.race([ new Promise((_, reject) => setTimeout(reject, 1000, 'Rejected!')), new Promise(resolve => setTimeout(resolve, 500, 'Resolved!')), ]) .then(console.log) // 'Resolved!' .catch(console.error); 4. Promise.allSettled This method is similar to Promise.all(), but it waits for all promises to settle(either resolve or reject), regardless of their result (resolve or reject). It returns an array of objects with the status of each promise. Promise.allSettled([ Promise.resolve('Good!'), Promise.reject('Bad!'), ]) .then(console.log); /* Output: [ { status: 'fulfilled', value: 'Good!' }, { status: 'rejected', reason: 'Bad!' } ] */ 5. Promise.resolve(value) Returns a Promise that is already resolved with the provided value. If the value is a promise, it returns that promise unchanged. Useful for ensuring consistent promise-based workflows, even for sync values. Promise.resolve(42).then(console.log); // 42 Promise.resolve(Promise.resolve('OK')) // Flattens the inner promise .then(console.log); // OK 6. Promise.reject(reason) Returns a Promise that is already rejected with the given reason. Often used to simulate errors in chains or early exits. Promise.reject('Error occurred') .catch(err => console.error(err)); // Error occurred Promise APIs or Promise Instance Methods Promise APIs are called on an actual promise object and are used to handle its result or error. 1. .then(onFulfilled, onRejected) Handles the resolved or rejected result of a Promise. Takes two optional callbacks: onFulfilled: runs when the promise is resolved. onRejected: runs when the promise is rejected. Handles promise fulfilment and rejection. Commonly used for chaining. fetch('/api') .then(response => response.json(), err => console.error(err)) .then(data => console.log(data)); 2. .catch(onRejected) Handles any rejection in the promise chain. Equivalent to .then(null, onRejected). Cleaner than using then with null. fetch('/api') .then(res => res.json()) .catch(err => console.error('Fetch failed:', 3. .finally(onFinally) Executes regardless of whether the promise is fulfilled or rejected. Often used for cleanup (e.g., stop loading spinner, close DB connections). Does not receive the resolved value or error. setLoading(true); doTask() .then(handleSuccess) .catch(handleError) .finally(() => setLoading(false)); Summary Promise Static Methods Promise.any: Resolves when any one promise resolves; rejects only if all fail. Promise.all: Waits for all to resolve; rejects if any one fails. Promise.race: Settles as soon as the first promise settles (resolve/reject). Promise.allSettled: Waits for all to settle; gives status of each (fulfilled/rejected). Promise.resolve(value): Instantly returns a resolved promise. Promise.reject(reason): Instantly returns a rejected promise. Promise APIs .then(): Handles both resolve and reject cases with optional callbacks. .catch(): Catches rejections in a clean way. .finally(): Executes cleanup logic after promise settles.

Here’s a lightning-quick refresher on promise static methods (.any, .all, .race, .allSettled, .resolve, .reject) and promise APIs (.then, .catch, .finally).
Promise Static Methods
Promise Static Methods are called on the Promise class itself, not on a promise instance. They help manage multiple promises.
1. Promise.any
- Takes an array of promises as input and returns a single promise.
- It will resolve if any of the promises in an array are resolved with the resolved value.
- If all the promises are rejected, promise will be rejected with the error “AggregateError: All promises were rejected”.
Promise.any([Promise.reject('Error!'), Promise.resolve('Success!')])
.then(console.log) // 'Success!'
.catch(console.error);
2. Promise.all
- This method takes an array of promises as input and returns a single promise.
- It resolves when all of the promises in the array have resolved, or rejects when any one of the promises rejects.
Promise.all([Promise.resolve('First'), Promise.resolve('Second')])
.then(console.log) // ['First', 'Second']
.catch(console.error);
3. Promise.race
- This method takes an array of promises as input and returns a single promise.
- It will return the promise as soon as any of the promises is settled(either resolved or rejected).
Promise.race([
new Promise((_, reject) => setTimeout(reject, 1000, 'Rejected!')),
new Promise(resolve => setTimeout(resolve, 500, 'Resolved!')),
])
.then(console.log) // 'Resolved!'
.catch(console.error);
4. Promise.allSettled
- This method is similar to Promise.all(), but it waits for all promises to settle(either resolve or reject), regardless of their result (
resolve
orreject
). - It returns an array of objects with the status of each promise.
Promise.allSettled([
Promise.resolve('Good!'),
Promise.reject('Bad!'),
])
.then(console.log);
/* Output:
[
{ status: 'fulfilled', value: 'Good!' },
{ status: 'rejected', reason: 'Bad!' }
]
*/
5. Promise.resolve(value)
- Returns a Promise that is already resolved with the provided value.
- If the value is a promise, it returns that promise unchanged.
- Useful for ensuring consistent promise-based workflows, even for sync values.
Promise.resolve(42).then(console.log); // 42
Promise.resolve(Promise.resolve('OK')) // Flattens the inner promise
.then(console.log); // OK
6. Promise.reject(reason)
- Returns a Promise that is already rejected with the given reason.
- Often used to simulate errors in chains or early exits.
Promise.reject('Error occurred')
.catch(err => console.error(err)); // Error occurred
Promise APIs or Promise Instance Methods
Promise APIs are called on an actual promise object and are used to handle its result or error.
1. .then(onFulfilled, onRejected)
- Handles the
resolved
orrejected
result of a Promise. - Takes two optional callbacks:
-
onFulfilled
: runs when the promise is resolved. -
onRejected
: runs when the promise is rejected.
-
- Handles promise fulfilment and rejection. Commonly used for chaining.
fetch('/api')
.then(response => response.json(), err => console.error(err))
.then(data => console.log(data));
2. .catch(onRejected)
- Handles any rejection in the promise chain.
- Equivalent to .then(null, onRejected).
- Cleaner than using then with null.
fetch('/api')
.then(res => res.json())
.catch(err => console.error('Fetch failed:',
3. .finally(onFinally)
- Executes regardless of whether the promise is fulfilled or rejected.
- Often used for cleanup (e.g., stop loading spinner, close DB connections).
- Does not receive the resolved value or error.
setLoading(true);
doTask()
.then(handleSuccess)
.catch(handleError)
.finally(() => setLoading(false));
Summary
Promise Static Methods
- Promise.any: Resolves when any one promise resolves; rejects only if all fail.
- Promise.all: Waits for all to resolve; rejects if any one fails.
- Promise.race: Settles as soon as the first promise settles (resolve/reject).
- Promise.allSettled: Waits for all to settle; gives status of each (fulfilled/rejected).
- Promise.resolve(value): Instantly returns a resolved promise.
- Promise.reject(reason): Instantly returns a rejected promise.
Promise APIs
- .then(): Handles both resolve and reject cases with optional callbacks.
- .catch(): Catches rejections in a clean way.
- .finally(): Executes cleanup logic after promise settles.