ควิซ JavaScript: Promise.all, allSettled, race & any

JavaScript has four ways to combine promises, and each one reacts differently to failures. This quiz tests Promise.all(), Promise.allSettled(), Promise.race() and Promise.any(), the order of their results and what they do when something rejects.

ปานกลาง 10 ข้อ ~6 นาที ผ่านที่ 80% Node.js 22

เลือกโหมด

กำลังเล่นแบบผู้เยี่ยมชม: เข้าสู่ระบบเพื่อเก็บ XP และ streak

ตัวอย่างคำถาม

ข้อ 1 จาก 10

What does this print?

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

Promise.all([wait(10, "slow"), wait(1, "fast"), 42])
  .then(results => console.log(results.join(",")));
ดูเฉลย

C. slow,fast,42 Promise.all() gives results in the same order as the input, no matter which finishes first. Plain values like 42 are treated as already resolved promises.

ควิซนี้มีเนื้อหาอะไรบ้าง

  • Promise.all() keeps input order and fails fast
  • Promise.allSettled() reports every result
  • Promise.race() settles with the first one to settle
  • Promise.any() and AggregateError
  • Choosing the right combinator for a real task

คำถามที่พบบ่อย

ต้องมีบัญชีไหม?

ไม่ต้อง ใครก็เล่นได้ เข้าสู่ระบบเพื่อเก็บ XP, streak, เหรียญตรา และประวัติ

ทำซ้ำได้ไหม?

ได้ ระบบเก็บคะแนนที่ดีที่สุดไว้ และสลับคำถามกับตัวเลือกใหม่ทุกครั้ง