Javascript Beyond Basics
1 min readApr 18, 2025
Learning the depth of JavaScript
Handling Multiple Promises
Promise.all() — Wait for all or fail fast
const p1 = Promise.resolve("🚀 Rocket");
const p2 = Promise.resolve("🪐 Planet");
Promise.all([p1, p2])
.then((results) => console.log(results)) // ["🚀 Rocket", "🪐 Planet"]
.catch((err) => console.log("Error:", err));const p1 = Promise.resolve("✅ Success");
const p2 = Promise.reject("💥 Boom!");
Promise.all([p1, p2])
.then(console.log)
.catch(console.error); // 💥 Boom!Promise.allSettled() — Wait for all, no matter what
Get Prince Kumar Chaurasia’s stories in your inbox
Join Medium for free to get updates from this writer.
That is your chill friend. It waits for everything, and gives you the status of each.
const p1 = Promise.resolve("🍕");
const p2 = Promise.reject("💣");
Promise.allSettled([p1, p2]).then(console.log);[
{ status: "fulfilled", value: "🍕" },
{ status: "rejected", reason: "💣" }
]Promise.race() — First to finish wins
const p1 = new Promise(res => setTimeout(() => res("🐢 Slow"), 2000));
const p2 = new Promise(res => setTimeout(() => res("🐇 Fast"), 500));
Promise.race([p1, p2]).then(console.log); // 🐇 FastPromise.any() — First successful one wins
const p1 = Promise.reject("❌");
const p2 = Promise.resolve("✅ Success");
const p3 = Promise.resolve("🎉 Another one");
Promise.any([p1, p2, p3]).then(console.log); // ✅ SuccessSee you in next one.


![Infinite Scroll using React & JavaScript — [Asked in Machine Coding Rounds of Big Tech Companies]](https://miro.medium.com/v2/resize:fit:1358/format:webp/1*hIqA_3mkWt9CLmJ4JXOGYw.jpeg)






