Recall & Review
beginner
What does the
then method do in JavaScript promises?The
then method runs a function when a promise is successfully completed (resolved). It lets you handle the result of the promise.Click to reveal answer
beginner
What is the purpose of the
catch method in promises?The
catch method runs a function when a promise fails (is rejected). It helps you handle errors or problems.Click to reveal answer
intermediate
How do
then and catch work together in promise chains?You use
then to handle success and catch to handle errors. This way, you can manage both outcomes in a clear, step-by-step way.Click to reveal answer
beginner
What happens if you don’t use
catch with a promise?If you don’t use
catch, errors in the promise might go unnoticed, causing bugs or unhandled promise rejections.Click to reveal answer
beginner
Show a simple example of using
then and catch with a promise.Example:<br>
fetch('https://api.example.com/data')
.then(response => response.json())
.then(data => console.log(data))
.catch(error => console.error('Error:', error));Click to reveal answer
What does the
then method do in a promise?✗ Incorrect
The
then method runs when the promise is resolved successfully.Which method is used to catch errors in a promise chain?
✗ Incorrect
The
catch method handles rejected promises or errors.What will happen if a promise is rejected but there is no
catch method?✗ Incorrect
Without
catch, errors can go unnoticed and cause warnings.Can you chain multiple
then methods?✗ Incorrect
You can chain many
then calls to process data step-by-step.What does this code do?<br>
promise.then(fn1).catch(fn2);
✗ Incorrect
then handles success with fn1, catch handles errors with fn2.Explain how
then and catch methods help manage asynchronous code in JavaScript.Think about how you handle good and bad outcomes in real life.
You got /4 concepts.
Describe a simple example where you would use
then and catch with a promise.Imagine getting data from the internet and handling success or failure.
You got /4 concepts.