Promises Flashcards

Get a fucking job

1
Q

What are the possible states of a promise?

A

Pending, fulfilled, rejected.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What is “new Promise()”?

A

A promise constructor. Creates promise objects.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What is a promise?

A

An object that represents the eventual completion of an asynchronous operation and its resulting value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What is “await”?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

What is a promise?

A

An object that represents the eventual completion of an async operation and its resulting value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Top-level await, what is it?

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

What is Promise.resolve()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What is Promise.reject()

A

Static method that returns a Promise object that is rejected with a given reason.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What is Promise.any()

A

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).

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

What is Promise.all()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What is .then()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

What is .catch()

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is .finally()

A

Instance method that runs either on fulfilled or rejected state of a promise.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly