Promises — States, Chaining and the Combinators — Concept Check
Questions on Promises — States, Chaining and the Combinators. A promise is a value that will exist later. It has three states, settles exactly once, and chains through .then — and the four combinators cover almost every multi-request situation.
Questions in this quiz
8 questions on Promises — States, Chaining and the Combinators — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.You have a promise chain where a .then handler does not return a value. What is the consequence?
- AThe next promise in the chain receives the previous value.
- BThe next promise in the chain receives undefined.
- CThe promise chain stops executing.
- DThe promise chain throws an error.
2.In a fetch operation with Promise.all, one request fails. What happens?
- AThe promise is fulfilled with undefined values for failed requests.
- BThe promise is rejected immediately.
- CAll requests are cancelled and the promise is rejected.
- DThe failed request is retried automatically.
3.A developer uses Promise.race with multiple API calls and a timeout. What is the purpose of this pattern?
- ATo use the result of the first successful API call.
- BTo ensure the fastest API call result is used.
- CTo cancel all API calls if one fails.
- DTo ensure all API calls are completed before timing out.
4.A promise is created with multiple resolve calls. What is the outcome?
- AThe promise resolves with the last call's value.
- BThe promise rejects if multiple resolve calls are made.
- CThe promise alternates between resolved and rejected states.
- DThe promise resolves with the first call and ignores subsequent calls.
5.What happens if you forget to return a promise inside a .then handler?
- AThe promise chain throws an error.
- BThe next .then receives undefined, breaking the chain.
- CThe chain automatically handles the missing return.
- DThe promise chain continues without issues.
6.Which combinator should you use if you need results from multiple promises regardless of their success or failure?
- APromise.race
- BPromise.allSettled
- CPromise.any
- DPromise.all
7.A developer uses Promise.any with multiple fetch requests. What happens if all requests fail?
- AThe promise resolves with undefined.
- BThe promise waits indefinitely.
- CThe promise is fulfilled with the last failed response.
- DThe promise is rejected with an AggregateError.
8.When is it appropriate to use sequential promise handling over parallel?
- AWhen all promises are independent of each other.
- BWhen there are dependencies between promises.
- CWhen you want to minimize resource usage.
- DWhen you want faster execution time.