Promises Flashcards
Get a fucking job
What are the possible states of a promise?
Pending, fulfilled, rejected.
What is “new Promise()”?
A promise constructor. Creates promise objects.
What is a promise?
An object that represents the eventual completion of an asynchronous operation and its resulting value.
What is “await”?
An operator used to wait for a Promise and get its fulfillment value. It can only be used inside an async function or at the top level of a module.
What is a promise?
An object that represents the eventual completion of an async operation and its resulting value.
Top-level await, what is it?
What is Promise.resolve()
Static method that resolves a given value to a Promise. If the value passed is a promise, that promise is returned. If the value is a thenable, Promise.resolve() will call the then() method with two callbacks it prepared. Otherwise, the returned promise will be fulfilled with the value.
What is Promise.reject()
Static method that returns a Promise object that is rejected with a given reason.
What is Promise.any()
Static method that takes an iterable of promises (array of promises) and returns a single Promise. The returned promise fulfills when any of the input promises fulfills, with its fulfillment value. It will only be rejected when all of the input promises are rejected (including passing an empty array).
What is Promise.all()
Static method that takes an array of promises as input and returns a single Promise. This returned promise fulfills when all the input’s promises fulfill (including an empty array), with an array of the fulfillment values. It rejects when any of the input’s promises rejects, with the reason.
What is .then()
Promise.prototype.then() is an instance method that takes up to two arguments, callback functions for the fulfilled and rejected cases of the Promise.
It stores the callbacks within the promise it is called on and immediately return another Promise object, allowing you to chain calls to other promise methods.
What is .catch()
Promise.prototype.catch() is an instance method that runs when the promise is rejected. It immediately returns another Promise object, allowing you to chain calls to other promise methods.
What is .finally()
Instance method that runs either on fulfilled or rejected state of a promise.