ASYNC JS: ES6 Promise.all method - unexpected output dilemma. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 10

ASYNC JS: ES6 Promise.all method - unexpected output dilemma.

My question is about why there are two expected outputs from sololearn challenges in this chunk of ajax code but when I test in the debugger this gives me only [foo, car] as output? const a = new Promise((res, rej) => { //n1     setTimeout(() => res('foo'), 300); }); const b = new Promise((res, rej) =>  {     setInterval(() => rej('bar'), 100);     res('car'); }); Promise.all([a, b]).then((race) => {     console.log(race); }).catch((crash) => {     console.log(crash); }); Right answers: [foo, car] ['bar', 'car'] - why this?

12th Apr 2019, 8:13 AM
Luis Febro 🇧🇷
Luis Febro 🇧🇷 - avatar
2 Answers
+ 11
I have not much idea about js promises but i can help you with this link.. https://stackoverflow.com/questions/55979096/ajax-promise-all-method-unexpected-output-dilemma
7th May 2019, 1:26 PM
Sarthak Pokhrel
Sarthak Pokhrel - avatar
7th May 2019, 1:27 PM
Sarthak Pokhrel
Sarthak Pokhrel - avatar