JS Promises Flashcards

1
Q

Which queue do callbacks from promises go to when waiting to be being executed?

A

The microtasks queue

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

How does these microtasks differ from the callbacks that enter the callback queue?

A

It has priority over the callback queue, meaning at the end of an event loop tick it’ll check the microtasks queue BEFORE running a task from the callback queue

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

What happens if a microtask generates another during exectution?

A

That new microtask would be executed before any other callback (even if they are there waiting in the callback queue)

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

Which arguments does a promise take?

A

Resolve & Reject

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

How do you create a promise?

A

new Promise( (resolve, reject) => { } );

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

What does calling resolve() mark the promise as?

A

Fulfilled

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

What does calling reject() mark the promise as?

A

Rejected

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

What state does the promise need to be in order to call .then() on it?

A

Resolved/Fulfilled

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

What is resolve()?

A

A static method on the Promise constructor where we pass in the resolved value of the promise

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

What is the different between passing in the resolved value like this: Promise.resolve(‘resolved value here’) as opposed to within a promise code block?

A

Promise.resolve(‘ ‘) will resolve the promise immediately.

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