Middle+
Name the promise methods (Promise.resolve, Promise.reject, and others)
sobes.tech AI
Answer from AI
Main methods of the Promise object in JavaScript:
Promise.resolve(value)— returns a promise that is immediately resolved with the valuevalue.Promise.reject(reason)— returns a promise that is immediately rejected with the reasonreason.Promise.all(iterable)— takes an iterable of promises and returns a promise that resolves to an array of results if all promises are fulfilled, or rejects with the first error.Promise.race(iterable)— returns a promise that resolves or rejects as soon as the first promise in the iterable resolves or rejects.Promise.allSettled(iterable)— returns a promise that resolves after all promises have settled, with an array of their results (fulfilled and rejected).Promise.any(iterable)— returns a promise that resolves with the first successfully fulfilled promise, or rejects if all promises are rejected.
Example usage:
Promise.resolve(42).then(value => console.log(value)); // 42
Promise.reject(new Error('Error')).catch(err => console.error(err));
Promise.all([Promise.resolve(1), Promise.resolve(2)])
.then(results => console.log(results)); // [1, 2]