Async/Await — Series 3

Preview — 3 of 10 questions

What is logged?

javascript
const delay = (ms, v) => new Promise((r) => setTimeout(() => r(v), ms));

Promise.any([Promise.reject(new Error('a')), delay(10, 'b')])
  .then((v) => console.log('any:', v));

Promise.any([Promise.reject(new Error('x')), Promise.reject(new Error('y'))])
  .catch((e) => console.log(e.constructor.name, e.errors.length));
Aany: a, then Error 2
BAggregateError 2, then any: b
CAggregateError 2, then any: b — the first rejection is ignored because a later input fulfils
Dany: b, then TypeError 2

What is logged?

javascript
Promise.allSettled([Promise.resolve(1), Promise.reject(new Error('no'))]).then((rs) => {
  console.log(JSON.stringify(rs.map((r) => (r.status === 'fulfilled' ? r.value : r.reason.message))));
});
A[1,"no"]
B[1]
C["fulfilled","rejected"]
D[1,null]

What is logged?

javascript
const delay = (ms, v) => new Promise((r) => setTimeout(() => r(v), ms));

async function run() {
  const start = Date.now();
  const [a, b] = await Promise.all([delay(50, 'a'), delay(50, 'b')]);
  console.log(a + b, Date.now() - start < 90);
}
run();
Aab false
Bba true
Cundefinedundefined true
Dab true

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.