JS Promises Flashcards
Which queue do callbacks from promises go to when waiting to be being executed?
The microtasks queue
How does these microtasks differ from the callbacks that enter the callback queue?
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
What happens if a microtask generates another during exectution?
That new microtask would be executed before any other callback (even if they are there waiting in the callback queue)
Which arguments does a promise take?
Resolve & Reject
How do you create a promise?
new Promise( (resolve, reject) => { } );
What does calling resolve() mark the promise as?
Fulfilled
What does calling reject() mark the promise as?
Rejected
What state does the promise need to be in order to call .then() on it?
Resolved/Fulfilled
What is resolve()?
A static method on the Promise constructor where we pass in the resolved value of the promise
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?
Promise.resolve(‘ ‘) will resolve the promise immediately.