Promises in Javascript
Yeah, Javascript(JS) has a mechanism called promises and it does exectly samething as we do with our promise. You heard it right it promises to caller that i'll give whatever you requested, I'll come back after working on this you might be busy now. Ahh, May be I'm confusing you. Let me give you exect story why I'm saying JS promise as Human promise.

Introduction
A promise is a object that represents eventual completion (or failure) of asyncronous operations.
Simple defination:
A placeholder for a future value.
Use of Promise:
To execute asyncronous code without blocking javascript's main thread.
To achieve parallelisiam.
Asyncronous codes like:
fetch
timer
some independent long running code
Initially, when we create a new Promise it gives an object containing status, prototype, result.
const promise = new Promise((resolve, reject)=>{});
console.log(promise);
Output
{
Prototype: Promise,
PromiseStatus: 'pending',
PromiseRestult: undefined
}
It has three state:
Pending: Shows the promise not completed execution yet.
Fullfilled: Shows excution completed successfully.
Failed: Show Excution failed.
Create a new Promise:
Most common ways to create promise is:
PromiseConstructor:
const user = new Promise((resolve, reject)=>{});
asyncFunction:
async function user(){
// Async operations here.
}
Both code chunks are same.
What are resolve and reject ?
These are callback functions use to mark success and failure respectively.
const img = new Prommise((resolve, reject)=>{
try{
// Some heavy calculation
resolve(enhancedImage);
}catch(error){
// If error happens
reject(error.message);
}
})
img.then((img)=>{
updateImageInDOM(img);
}).catch((error)=>{
console.error(error);
});
Error handling in Promise:
.catch() method is used to catch any error from promise. like in the above example.
Then comes .finally() , It runs reagardless of failure or success.
We can use finally when we need to do something on completion either it's success or failure.
fetch('https://jsonplaceholder.typicode.com/users')
.then((data)=>
data.json()
).catch((error)=>{
console.error(error.message);
}).finally(notify);
Usefull Promise Utilities:
Promise.all(): Gets array of promises and waits for all to complete if anyone fails, It complete failure.
Best for Initial load to fetch all essential data.Promise.allSettled(): Gets array of promises and returns result of each.
Best for bulk async operations.Promise.race(): Gets array of promises and returns first settled one.
Best for multiplayer quick quiz scenario.Promise.any(): Gets array of promises and returns the first fullfilled promise.
Best for multiplayer quick quiz scenario.
Remember:
.then()callback goes into Microtask Queue, Because Promise callbacks never execute synchronously.
Promise CheetSheet for quick revision.
👋 Thanks for Reading
If this article helped you understand Promises in JavaScript, consider sharing it with fellow developers.
Connect With Me
LinkedIn: https://www.linkedin.com/in/devankesh/
Have Questions?
Drop your thoughts in the comments. I'd love to discuss ideas, answer questions, and learn from your perspective.
Follow for More
I write about:
JavaScript
TypeScript
React
Frontend Architecture
Web Performance
Software Engineering
⭐ Follow me on Hashnode to stay updated with new articles.
About the author
- I build fast, user-friendly web applications that help teams ship better digital products. My focus is on responsive UI, clean architecture, and production-ready frontend systems. Over the past 2+ years, I’ve worked with React, Angular, and TypeScript building real-world applications, integrating APIs, and delivering reliable user experiences in production environments. I’ve also worked with headless CMS solutions like Strapi and Drupal using GraphQL to enable dynamic content and structured systems. I care about writing maintainable, component-driven code and optimizing performance across devices. This blog is where I document what I build, what breaks, and what actually works in real projects. Lately, I’m exploring the shift from writing code to thinking in terms of products understanding users, systems, and decisions behind what we build.
Comments
Join the discussionNo comments yet. Be the first to comment.
JavaScript Essentials
JavaScript powers the modern web, from interactive websites to full-stack applications. This series is designed for beginners, self-taught developers, and frontend engineers who want to build a strong understanding of JavaScript fundamentals before moving into frameworks like React, Angular, or Next.js. Each article focuses on one concept at a time with: Simple explanations Visual diagrams Real-world examples Interview insights Common mistakes Best practices Whether you're preparing for interviews, improving frontend skills, or revisiting core concepts, this series will help you build a solid JavaScript foundation.

