5-min frontend part-3
const promise1 = Promise.resolve('First')
const promise2 = Promise.resolve('Second')
const promise3 = Promise.reject('Third')
const promise4 = Promise.resolve('Fourth')
const runPromises = async () => {
const res1 = await Promise.all([promise1, promise2])
const res2 = await Promise.all([promise3, promise4])
return [res1, res2]
}
runPromises()
.then(res => console.log(res))
.catch(err => console.log(err))
Answer "Third"
So here we are using Promise.all so what happens in promise.all is if one promise fails it will automatically return that error , that's the reason it will print Third so it is getting returned from runPromises
Thank you have a great day ahead