JavaScript Promise Methods: A Quick Guide

Day 4 ⚡ JavaScript Promise Methods — Quick Guide If you're working with async JavaScript, knowing these Promise methods can level up your coding and interviews 🚀 🧠 1. Promise.all() 👉 Runs all promises in parallel 👉 Fails if any one fails Promise.all([p1, p2, p3]) .then(res => console.log(res)); 🟡 2. Promise.allSettled() 👉 Waits for all promises (success + failure) Promise.allSettled([p1, p2]) .then(res => console.log(res)); 🏁 3. Promise.race() 👉 Returns the first completed promise Promise.race([p1, p2]) .then(res => console.log(res)); 🥇 4. Promise.any() 👉 Returns the first successful promise Promise.any([p1, p2]) .then(res => console.log(res)); 🔧 5. Promise.resolve() 👉 Creates a resolved promise Promise.resolve("Done"); ❌ 6. Promise.reject() 👉 Creates a rejected promise Promise.reject("Error"); 🧠 Quick Tip: Use all → when all must succeed Use allSettled → when you want all results Use race → fastest result Use any → first success 💡 One-line takeaway: 👉 Choose the right Promise method based on how you want async tasks to behave #JavaScript #WebDevelopment #Frontend #Coding #100DaysOfCode

To view or add a comment, sign in

Explore content categories