Skip to main content

Command Palette

Search for a command to run...

JavaScript Promise Methods Explained in Meme style

Updated
6 min read
JavaScript Promise Methods Explained in Meme style
S

Building Web & GenAI Software that (usually) work | Son of proud parents.

Promises in JavaScript are just like real-life promises: they are either kept (resolved), broken (rejected), or you are just left waiting (pending). But when you have multiple promises happening at the same time, JavaScript gives us four special methods to handle them.

Let's understand them not with boring definitions, but with the memes we grew up with!

1. Promise.all() – The Goa Trip Rule 🌴

Promise.all() takes an array of promises and runs them together. It has one strict rule: All promises must succeed. If even one promise fails (rejects), the entire Promise.all() instantly fails and throws an error.

Think of planning a Group Trip to Goa with your friends. You need permissions from everyone's parents.

  • Rencho’s parents agreed (Resolved).

  • Raju’s father said: agreed (Resolved).

  • Farhan’s parents "Nahi jayega mera beta!" (Rejected).

    Because one friend backed out, the whole trip is immediately CANCELLED. The success of the trip strictly depends on everyone saying yes.

The Code:

const renchoGoa = Promise.resolve("Rencho is in!");
const rajuGoa = Promise.resolve("Raju is in!");
const farhanGoa = Promise.reject("Abba nahi manenge!"); 

Promise.all([renchoGoa, rajuGoa, farhanGoa])
  .then((results) => {
    console.log("Goa Trip ON!", results);
  })
  .catch((error) => {
    console.log("Trip Cancelled because:", error); 
    // Output: Trip Cancelled because: Abba nahi manenge!
  });

2. Promise.allSettled() – The University Results Day 📝

Promise.allSettled() also takes an array of promises, but it is super patient. It waits for all promises to finish, regardless of whether they pass (resolve) or fail (reject). It never short-circuits. It just gives you a final report card of what happened to everyone.

Think of Engineering Semester Results. The university doesn't stop publishing the result sheet just because one student failed.

Whether you topped the class (Resolved) or got a backlog (Rejected), the university waits for all papers to be checked and then publishes the final list showing the exact status of every student. It’s like Sachiv Ji from Panchayat patiently making a list of everyone in the village some got the scheme, some didn't, but he notes down everyone's final status.

The Code:

const student1 = Promise.resolve("Pass: 9.8 CGPA");
const student2 = Promise.reject("Fail: Backlog in Math");
const student3 = Promise.resolve("Pass: 7.5 CGPA");

Promise.allSettled([student1, student2, student3])
  .then((reportCard) => {
    console.log(reportCard);
    /* Output:
      [
        { status: "fulfilled", value: "Pass: 9.8 CGPA" },
        { status: "rejected", reason: "Fail: Backlog in Math" },
        { status: "fulfilled", value: "Pass: 7.5 CGPA" }
      ]
    */
  });

3. Promise.race() – The IRCTC Tatkal Booking 🚂

Promise.race() is exactly what it sounds like. It takes an array of promises and returns the result of the very first one to finish. It does not care if the first one resolves or rejects; whoever crosses the finish line first, wins the race.

This is the IRCTC Tatkal Ticket Booking race at exactly 10:00 AM.

Thousands of people are hitting the "Book" button at the exact same millisecond.

  • If your payment gateway is the fastest to process, you get the ticket (First to Resolve = You win).

  • If the IRCTC server crashes for you first before anyone else's payment goes through, you get an error screen (First to Reject = You lose).

    Whatever happens first is the final outcome. The rest of the requests are ignored.

The Code:

const tatkalSuccess = new Promise((resolve) => setTimeout(resolve, 500, "Ticket Confirmed!"));
const serverCrash = new Promise((_, reject) => setTimeout(reject, 200, "503 Service Unavailable"));

Promise.race([tatkalSuccess, serverCrash])
  .then((result) => console.log(result))
  .catch((error) => console.log("Race Result:", error)); 
  // Output: Race Result: 503 Service Unavailable (because 200ms is faster than 500ms)

4. Promise.any() – The Job Placement / Arranged Marriage Hack 💼💍

Promise.any() is the most optimistic method. It waits for the first promise to successfully resolve. It completely ignores all rejections (failures) unless every single promise fails, in which case it throws an AggregateError.

Think of Off-Campus Job Hunting (or an Arranged Marriage setup).

You apply to 10 different companies.

  • TCS rejects you (Ignored).

  • Infosys rejects you (Ignored).

  • Wipro says YES! (Resolved).

    You don't care about the rejections! You only need ONE success to get a job. Promise.any() ignores the "No"s and instantly celebrates the first "Yes". It only gets sad if every single company rejects you (the dreaded AggregateError).

Here is more relatable example

The Code:

const tcs = Promise.reject("HR round failed");
const infosys = Promise.reject("Aptitude failed");
const wipro = new Promise((resolve) => setTimeout(resolve, 1000, "Offer Letter Received!"));

Promise.any([tcs, infosys, wipro])
  .then((job) => {
    console.log("Status:", job); 
    // Output: Status: Offer Letter Received! (Ignored the rejections!)
  })
  .catch((error) => {
    console.log("All rejected:", error.errors); 
    // Only runs if literally ALL of them reject.
  });

Conclusion: The Happy Ending

JavaScript Promises can sometimes feel like an Ekta Kapoor daily soap, lots of endless waiting (Pending), dramatic betrayals (Rejected), and occasional happy moments (Resolved). But when you have to handle multiple APIs, database calls, or timers all at once, you don't need to panic. You are not a confused side-character anymore; you are the Director!

Just remember the golden rules of your script:

  • Want a strict "All or Nothing" Goa plan? Call your strict dad, Promise.all().

  • Want a patient Report Card of everyone's drama without stopping the show? Hand the register to Promise.allSettled().

  • Want to survive the Tatkal Hunger Games where only speed matters? Run the Promise.race().

  • Desperate for just ONE piece of good news while ignoring the rejections? Live your best solo life with Promise.any().

Unlike real life, where a bad date might ghost you and leave you in the Pending state forever, JavaScript will eventually give you an answer. You just need to know how to handle it.

So, get ready with your inner Faizal, open your VS Code, and tell your compiler: "Baap ka, dada ka, bhai ka... sabka API call resolve karega tera JavaScript!"

Quick Summary Cheat Sheet:

  • Promise.all(): All must pass. (Goa trip - one cancels, all cancelled).

  • Promise.allSettled(): Waits for all, returns a report card. (University results).

  • Promise.race(): First to finish wins, pass or fail. (IRCTC Tatkal).

  • Promise.any(): First to pass wins, ignores fails. (Job hunting).