JavaScript · Middle · Question 22 of 75

What does the chain print?

Promise.resolve(1)
  .then(x => x + 1)
  .then(x => { throw new Error(String(x)); })
  .catch(e => e.message)
  .then(x => console.log(x));

Explanation

The value returned from then is passed along. An error skips then handlers until the nearest catch, and catch returns a normal value ('2'), after which the chain continues as fulfilled.

Further reading

Problem with a question

JavaScript · Middle · question 22

Test yourself

Take the JavaScript · Middle quiz: questions and options are shuffled, and you get a review of your mistakes at the end.

Take this quiz