Skip to main content

Command Palette

Search for a command to run...

Promises in JavaScript Explained Through a Real-Life Date Story

Updated
β€’5 min readβ€’View as Markdown
 Promises in JavaScript Explained Through a Real-Life Date Story
P

Software Engineer | Passionate about Web Development, DSA & Problem Solving. I write simple, practical tech blogs to help developers learn and grow. Exploring JavaScript, C++, Backend & Modern Web Technologies.

What is a Promise in JavaScript?

A Promise in JavaScript is an object that represents the future result of an asynchronous operation.

In simple words :
A Promise is a guarantee that something will happen later, not right now.

That β€œsomething” can be:

  • βœ… successful

  • ❌ failed

But one thing is sure:
πŸ‘‰ JavaScript will not stay silent. It will respond.

Just like real life… especially relationships πŸ˜„

πŸ€” Why Do We Even Need Promises?

JavaScript is non-blocking.

That means:

  • JavaScript does not wait

  • It keeps running the next line

  • Long tasks happen in the background

Examples of async tasks:

  • API calls 🌐

  • Timers ⏱

  • File uploads

  • Database requests πŸ—„

Without Promises, handling these tasks becomes messy and confusing.

πŸ”„ Promise States

Every Promise always stays in one of three states:

1️⃣ Pending – Work has started, result not ready
2️⃣ Fulfilled – Work completed successfully
3️⃣ Rejected – Work failed with a reason

πŸ’Œ JavaScript Promise States – A Love & Date Story

Piyush Gurg’s sir Date Night Plan

Piyush Gurg sir is single πŸ’™
Focused on his career πŸ‘¨β€πŸ’»
But like every human, he also believes in connection.

One evening, he plans a date.
Once the plan is made, the result is no longer in his control.

Exactly like a JavaScript Promise.

⏳ Pending State – The Waiting Phase

Piyush sir reaches the cafΓ© on time.

He orders coffee β˜•

He sits quietly and checks his phone πŸ“±

The date may happen

or may not happen

Nothing is confirmed yet.

JavaScript Meaning:

promiseState = "PENDING";

🧠 Explanation:

  • Promise has started

  • JavaScript is waiting

  • No success, no failure yet

Just like Piyush sir waiting at the table 😌

πŸ’– Fulfilled State – When Everything Goes Right

She arrives with a smile 😊

Conversation flows naturally

Time passes quickly

The date is successful ❀️

JavaScript Meaning:

promiseState = "FULFILLED";

🧠 Explanation:

  • Async task completed

  • Promise returned a value

  • Success path executed

This is the best-case scenario in both life and code.

πŸ’” Rejected State – When Plans Fall Apart

No reply.

No message.

No explanation.

Piyush sir waits… then leaves.

JavaScript Meaning:

promiseState = "REJECTED";

🧠 Explanation:

  • Async task failed

  • Promise returned a reason

  • Error must be handled

Promises don’t hide failures β€” they communicate them clearly.

JavaScript Code Example – Date as a Promise

function dateNight() {
  return new Promise((resolve, reject) => {

    // ⏳ Promise starts here (Pending state)
    console.log("Piyush sir is waiting for the date...");

    setTimeout(() => {
      const sheArrived = true; // change to false to see rejection

      if (sheArrived) {
        // βœ… Fulfilled state
        resolve("The date went really well ❀️");
      } else {
        // ❌ Rejected state
        reject("The date got cancelled πŸ’”");
      }

    }, 2000); // waiting time
  });
}

// Handling the Promise
dateNight()
  .then((successMessage) => {
    // Runs when resolve() is called
    console.log("SUCCESS:", successMessage);
  })
  .catch((errorMessage) => {
    // Runs when reject() is called
    console.log("FAILURE:", errorMessage);
  })
  .finally(() => {
    // Runs in both cases
    console.log("Date plan closed. Moving on πŸšΆβ€β™‚οΈ");
  });

Promise Methods Explained

.then() – After Success

Runs only when the Promise is fulfilled.

Meaning:
Piyush sir’s date went well.
Good conversation, good vibes.
So after success, he plans the next meet confidently.

promise.then((result) => {
  console.log(result);
});

.catch()– Handling Rejection

Runs only when the Promise is rejected.

Meaning:

The date got cancelled.
Piyush sir didn’t panic or overreact.
He accepted the situation calmly and moved on.

promise.catch((error) => {
  console.log(error);
});

.finally() – Closure Is Important

Runs no matter what happens.

Just like life β€”

success ho ya failure, closure zaroori hai.

Date successful ho ya cancel,
Piyush sir still goes home, reflects, and sleeps peacefully.
No loose ends.

promise.finally(() => {
  console.log("Emotional cleanup done 🧠");
});

Multiple Promises – Real-Life Situations

Promise.all() – Everything Must Work

Meaning:

Piyush sir planned dinner, movie, and cab.
If even one plan failed, the whole night failed.

Promise.all([bookTable(), orderFood(), arrangeRide()])
  .then(() => {
    console.log("Perfect date setup ❀️");
  });

Fails if even one task fails.

😊 Promise.any() – One Success Is Enough

Meaning:

Several plans didn’t work.
But one meaningful conversation clicked β€” and that was enough.

Promise.any([firstDate(), secondDate(), blindDate()])
  .then((result) => {
    console.log("At least one connection worked πŸ’«");
  });

πŸ“ Promise.allSettled() – Accepting All Outcomes

Meaning:

Some dates were good.
Some were awkward.
Piyush sir accepted every experience as a lesson.

Promise.allSettled([dateOne(), dateTwo()])
  .then((results) => {
    console.log(results);
  });

Success + failure β€” both matter.

⚑ Promise.race() – Whoever Responds First

Meaning:

Whoever replied first β€” that plan moved forward.
Timing matters.

Promise.race([replyFromHer(), replyFromOther()])
  .then((result) => {
    console.log("First response received πŸ“©", result);
  });

🎯 Conclusion

JavaScript Promises teach us an important life lesson:

  • You can’t control outcomes

  • You can only handle them correctly

Promises help us:

  • write clean async code ✨

  • avoid callback hell 😡

  • manage success and failure clearly

Just like relationships ❀️

**Wait patiently.

Handle responses honestly.

And always close the loop.**