JavaScript Promises Explained (and How Async/Await Makes Them Sweeter)
What do pizza orders, package tracking, and JavaScript have in common? More than you think..
Imagine you go to your favorite pizza place to order a large pizza. The moment you place the order, they don’t give you the pizza immediately — instead, they hand you a receipt with an order number.
Everyone’s happy:
It’s a win-win. And in programming, Promises do the same — they let you order up some data or a task, and get notified when it’s ready without blocking everything else.
The Programming Analogy
In JavaScript, this maps to:
A Promise ensures that once the result is ready (or an error occurs), all “subscribed” consumers get notified.
Think of it like package tracking:
The Executor: Where the Work Happens
When you write:
You can also think of this like booking concert tickets online:
Promise Internals
A Promise internally tracks two hidden properties:
Recommended by LinkedIn
You can’t directly access these, but you can work with them using .then(), .catch(), and .finally().
It’s like checking your package’s tracking page: you can see the status (“out for delivery”) but you don’t have the driver’s steering wheel in your hands.
Consuming Promises
For success only:
For errors only:
.catch(f) is just a cleaner version of .then(null, f).
How async/await Fits In
async/await doesn’t replace Promises — it’s built on top of them. You can think of it as syntactic sugar for writing asynchronous code in a synchronous-looking style.
Here’s what that means:
The difference is readability:
Final Thoughts
Think of .then() as carefully tracking your pizza order number and waiting for the call, and async/await as having the chef personally bring the pizza to your table exactly when it’s ready.
The pizza is the same — but the experience feels different. And whether you’re ordering pizza, waiting for a package, or showing up for a movie you pre-booked, the underlying pattern is the same: request → wait → receive → enjoy.
I really enjoyed reading this article. This type of initiative really helps to understand the things more precisely and effectively. It would be immensely valuable if you continue writing in this manner. Truly appreciable!
Love this, Manish.. very insightful do continue writing these articles.
Manish, thank you very much. This has truly strengthened my foundational knowledge. I had been using async and await without fully understanding how they work, so this explanation has been extremely valuable.
Definitely worth reading
That sounds like such a fun way to explain Promises! 🍕 Can’t wait to read your article.