All Challengesintermediate
Promise chaining order
Understanding the order of operations in Promise chains is critical for debugging AI code.
promiseschainingasyncerror handling
javascript
function processOrder(orderId) {
return fetch(`/api/orders/${orderId}`)
.then(res => res.json())
.then(order => {
if (order.status === 'pending') {
return fetch(`/api/orders/${orderId}/confirm`, { method: 'POST' })
}
return order
})
.then(result => {
if (result instanceof Response) {
return result.json()
}
return result
})
.catch(err => {
console.error('Order failed:', err)
return null
})
}Question
If the order status is "shipped", what does the second .then receive as its argument?