+ 4

A question from JavaScript challenges

I've met such question: What is the output of following code? const a = new Promise((res, rej) => { 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); }); And there were two right options: ['foo', 'car'] and ['bar', 'car']. I checked the code in Chrome console and it always printed only ['foo', 'car']. I guess the promise at `b` variable is resolved instantly, and it cannot become rejected in 100 ms because it already resolved. Also, as I've understood from 'https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/all', in the case of `b` promise rejection, a promise from Promise.all should reject with 'bar' value and no array. So, how can ['bar', 'car'] be a correct option?

13th Jun 2020, 6:24 PM
SergeiRom
1 ответ
+ 2
I think you are right. If you found it here in Sololearn you should use the report feature (top right corner) of the quiz.
14th Jun 2020, 5:40 AM
Kevin ★