Promise State
What is the initial state of a Promise when it is first created?
- Fulfilled
- Rejected
- Pending
- Settled
- Resolved
Promise Chaining
How do you chain multiple asynchronous operations using Promises?
- Using nested callbacks
- Using the 'await' keyword
- By returning a new Promise in each '.then()' callback
- With synchronous functions
- By defining async variables
Handling Errors
Which method is used to handle errors in a Promise chain?
- .catch()
- .finally()
- .then()
- .error()
- .except()
Promise.all()
What does the Promise.all() method do?
- Executes promises sequentially.
- Resolves when all promises in an iterable have resolved or rejects when any promise rejects.
- Rejects when all promises in an iterable have rejected.
- Resolves only the fastest promise.
- Resolves the last promise in the iterable.
Promise.race()
What does the Promise.race() method do?
- Resolves when all promises in an iterable have resolved.
- Resolves or rejects as soon as one of the promises in an iterable resolves or rejects.
- Rejects when all promises in an iterable have rejected.
- Resolves only the slowest promise.
- Runs all the promises at the same time.
Async/Await Syntax
Which keyword is used to pause the execution of an async function until a Promise is resolved?
- pause
- then
- wait
- await
- resolve
Purpose of Finally
What is the purpose of the '.finally()' method in a Promise?
- To handle errors
- To execute code after a Promise is either resolved or rejected, regardless of the outcome
- To resolve the promise
- To chain promises together
- To reject the promise
Fetching Data
When using the `fetch` API, what method is typically used to extract JSON data from the response?
- .json()
- .text()
- .data()
- .parseJSON()
- .fromJSON()
Catching Errors with Async/Await
How should you handle errors within an `async` function?
- Using a '.catch()' block directly after the 'await' statement.
- Wrapping the 'await' statement in a try...catch block.
- Using a global error handler.
- With .error()
- Ignoring the error, it will be handled automatically
Creating a Resolved Promise
How do you create a Promise that is immediately resolved with a specific value?
- new Promise.resolve(value)
- Promise.create(value)
- Promise.resolve(value)
- new ResolvedPromise(value)
- Promise(value)