{"id":98755,"date":"2026-01-21T16:42:41","date_gmt":"2026-01-21T11:12:41","guid":{"rendered":"https:\/\/www.guvi.in\/blog\/?p=98755"},"modified":"2026-09-08T13:55:21","modified_gmt":"2026-09-08T08:25:21","slug":"what-is-promise-in-javascript","status":"publish","type":"post","link":"https:\/\/www.guvi.in\/blog\/what-is-promise-in-javascript\/","title":{"rendered":"What is a Promise in JavaScript? A Complete Guide"},"content":{"rendered":"\n<p>A promise in JavaScript is an object that stands in for a future value, which is either resolved (success) or rejected (failure). If you have ever written code that depends on data from an API, a file, or a timer, you have already run into the problem promises were built to solve.<\/p>\n\n\n\n<p>Before promises existed, developers stacked callbacks inside callbacks just to keep things running in order, and it got messy fast. Promises cleaned that up, giving your code a cleaner way to say &#8220;do this, then this, then this&#8221; without losing your mind.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>TL;DR Summary<\/strong><\/h2>\n\n\n\n<ul>\n<li>A promise in javascript is an object that stands in for a future value, either resolved on success or rejected on failure, and this blog breaks down exactly how that works from the ground up.<\/li>\n\n\n\n<li>You&#8217;ll see the three states a promise in JavaScript moves through (pending, fulfilled, rejected), how to actually create one with the <code>Promise<\/code> constructor, and how to consume it using <code>.then()<\/code>, <code>.catch()<\/code>, and <code>.finally()<\/code>.<\/li>\n\n\n\n<li>Chaining, callbacks vs promises, and async\/await are all covered side by side, so you know exactly when to reach for which one instead of guessing.<\/li>\n\n\n\n<li>If you&#8217;re dealing with multiple promises at once, this blog walks through <code>Promise.all()<\/code>, <code>Promise.allSettled()<\/code>, <code>Promise.race()<\/code>, and <code>Promise.any()<\/code>, with real code for each.<\/li>\n\n\n\n<li>By the end, you&#8217;ll know the common mistakes developers make with a promise in JavaScript.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>What is a Promise in JavaScript?<\/strong><\/h2>\n\n\n\n<p><span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">A promise in&nbsp;<a href=\"https:\/\/www.guvi.in\/hub\/javascript\/\" target=\"_blank\" rel=\"noopener\">JavaScript<\/a>&nbsp;is an object that represents the eventual result of an <a href=\"https:\/\/www.guvi.in\/blog\/asynchronous-operations-in-javascript\/\" target=\"_blank\" rel=\"noreferrer noopener\">asynchronous operation<\/a> (tasks that run in the background instead of blocking your code while they finish), either a resolved value on success or a reason for rejection on failure.<\/span><\/p>\n\n\n\n<p><strong>Example: <\/strong><em><strong>Online Food Ordering.<\/strong><\/em> You place an order and get a receipt instead of the food itself. That receipt is a promise in JavaScript. The promise doesn&#8217;t give you the result right away, but it guarantees you&#8217;ll get an outcome: either the food arrives (resolved) or the order gets cancelled (rejected).<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const order = new Promise((resolve, reject) =&gt; {\n  resolve(\"Food delivered!\");\n});\n\norder.then((result) =&gt; console.log(result));<\/code><\/pre>\n\n\n\n<p>You place the order (create the promise), and <code>.then()<\/code> you&#8217;re waiting to see what happens once it resolves. No freezing, no blocking; your code just moves on and reacts when the result shows up.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p><strong><em>Build the Skills to Land a Software Engineering Job. HCL GUVI&#8217;s <\/em><\/strong><em><a href=\"https:\/\/www.guvi.in\/zen-class\/full-stack-development-course\/?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=promise-in-javascript\" target=\"_blank\" rel=\"noreferrer noopener\">Software and AI Engineer Programme<\/a><\/em><strong><em> takes you from programming fundamentals to full-stack and backend development, with mentor support, real projects, and dedicated interview prep, so you come out job-ready for the roles top companies are hiring for.<\/em><\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<div style=\"background-color: #099f4e; border: 3px solid #110053; border-radius: 12px; padding: 18px 22px; color: #FFFFFF; font-size: 18px; font-family: Montserrat, Helvetica, sans-serif; line-height: 1.6; box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15); max-width: 750px;\">\n  <strong style=\"font-size: 22px; color: #ffffff;\">\ud83d\udca1 Did You Know?<\/strong> <br \/><br \/>\n  <span>\n   <strong style=\"color: #110053;\"> Promises<\/strong> were officially added to <strong style=\"color: #110053;\">JavaScript in ES6 (2015)<\/strong> \n    to fix the <strong style=\"color: #110053;\">&#8220;callback hell&#8221;<\/strong> problem developers had struggled with for years.\n  <\/span>\n<\/div>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Why Do We Need Promises in JavaScript?<\/strong><\/h2>\n\n\n\n<p>Before promises, JavaScript developers had one real tool for async work: <a href=\"https:\/\/www.guvi.in\/blog\/callback-function-in-javascript\/\" target=\"_blank\" rel=\"noreferrer noopener\">callbacks<\/a>. <\/p>\n\n\n\n<p>And callbacks work fine until your code needs to do three or four things in order; then you end up with nested functions inside functions inside functions, impossible to read and even harder to debug. This is exactly the mess a promise in JavaScript was built to clean up.<\/p>\n\n\n\n<p>Here&#8217;s what promises actually solve:<\/p>\n\n\n\n<ul>\n<li><strong>No more callback hell<\/strong>: Instead of nesting functions inside each other, you chain steps one after another in a flat, readable line.<\/li>\n\n\n\n<li><strong>Better error handling<\/strong>: One <code>.catch()<\/code> can handle errors from an entire chain, instead of checking for errors at every single step.<\/li>\n\n\n\n<li><strong>Predictable async flow<\/strong>: You always know whether an operation succeeded or failed; there&#8217;s no guessing or manually checking flags.<\/li>\n\n\n\n<li><strong>Cleaner code with async\/await<\/strong>: Promises are the foundation that makes async\/await possible, which reads almost like normal, synchronous code.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<p><strong><em>Grab HCL GUVI&#8217;s free<\/em><\/strong><em> <a href=\"https:\/\/www.guvi.in\/mlp\/react-ebook?utm_source=blog&amp;utm_medium=hyperlink&amp;utm_campaign=promise-in-javascript\" target=\"_blank\" rel=\"noreferrer noopener\">React eBook<\/a><\/em><strong><em> and go from JSX basics to hooks and reusable components, built for anyone leveling up their React skills.<\/em><\/strong><\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>States of a Promise in JavaScript (Pending, Fulfilled, Rejected)<\/strong><\/h2>\n\n\n\n<p>Every promise in JavaScript moves through one of three states, and it can only ever be in one at a time. Once it settles into fulfilled or rejected, that&#8217;s final; it won&#8217;t change again.<\/p>\n\n\n\n<ul>\n<li><strong>Pending<\/strong>: The starting point. The async operation hasn&#8217;t finished yet, so there&#8217;s no result to give you.<\/li>\n\n\n\n<li><strong>Fulfilled<\/strong>: The operation completed successfully, and you now have the value you were waiting for.<\/li>\n\n\n\n<li><strong>Rejected<\/strong>: Something went wrong, and instead of a value, you get a reason for the failure.<\/li>\n<\/ul>\n\n\n\n<p>Think of it like tracking a package. It&#8217;s pending while it&#8217;s still on the way, fulfilled once it lands on your doorstep, and rejected if it gets lost or returned to sender.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Create a Promise in JavaScript<\/strong><\/h2>\n\n\n\n<p>Creating a promise in JavaScript comes down to the <code>Promise<\/code> constructor, which takes a function with two parameters: <code>resolve<\/code> and <code>reject<\/code>. You call one or the other depending on how the operation turns out.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const myPromise = new Promise((resolve, reject) =&gt; {\n  const success = true;\n\n  if (success) {\n    resolve(\"Task completed!\");\n  } else {\n    reject(\"Task failed.\");\n  }\n});<\/code><\/pre>\n\n\n\n<p>Inside the function, you run whatever async logic you need, then call <code>resolve(value)<\/code> when it works or <code>reject(error)<\/code> when it doesn&#8217;t. <\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>How to Use a Promise in JavaScript<\/strong><\/h2>\n\n\n\n<p>Creating a promise in JavaScript is only half the job; you also need a way to actually get the result out of it once it settles. That&#8217;s where consuming methods like <code>.then()<\/code>, chaining, and <code>async\/await<\/code> come in. Below are the core ways you&#8217;ll use promises in real code.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Promise.then(), catch(), and finally() Explained<\/strong><\/h3>\n\n\n\n<p>Once you have a promise, <code>.then()<\/code> is how you consume it; it runs when the promise resolves and hands you the value. <code>.catch()<\/code> does the same thing but for when the promise rejects, and <code>.finally()<\/code> runs no matter what happened, success or failure.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const order = new Promise((resolve, reject) =&gt; {\n  const isAvailable = true;\n\n  if (isAvailable) {\n    resolve(\"Pizza is on the way!\");\n  } else {\n    reject(\"Sorry, pizza is out of stock.\");\n  }\n});\n\norder\n  .then((result) =&gt; {\n    console.log(result);\n  })\n  .catch((error) =&gt; {\n    console.log(error);\n  })\n  .finally(() =&gt; {\n    console.log(\"Order process finished.\");\n  });\n<\/code><\/pre>\n\n\n\n<p><strong><em>Code Explanation:<\/em><\/strong><\/p>\n\n\n\n<ul>\n<li>The <code>order<\/code> promise checks if <code>isAvailable<\/code> is true.<\/li>\n\n\n\n<li>Since it&#8217;s true, it calls <code>resolve(\"Pizza is on the way!\")<\/code>.<\/li>\n\n\n\n<li>That resolved value is exactly what <code>.then()<\/code> receives as its <code>result<\/code> parameter.<\/li>\n\n\n\n<li>This is why <code>console.log(result)<\/code> prints &#8220;Pizza is on the way!&#8221;.<\/li>\n\n\n\n<li>If <code>isAvailable<\/code> had been false, <code>reject()<\/code> would run instead, and <code>.catch()<\/code> would catch that error message.<\/li>\n\n\n\n<li><code>.finally()<\/code> fires at the end no matter which branch ran; since it doesn&#8217;t care about success or failure, it just marks the promise as settled.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. How to Chain Promises in JavaScript<\/strong><\/h3>\n\n\n\n<p>A promise in JavaScript can be chained when one async step depends on the result of a previous one. Each <code>.then()<\/code> returns a new promise, so you can keep stacking them instead of nesting callbacks inside each other.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>function getUser() {\n  return new Promise((resolve) =&gt; {\n    resolve({ id: 1, name: \"Alex\" });\n  });\n}\n\nfunction getOrders(user) {\n  return new Promise((resolve) =&gt; {\n    resolve(`Orders for ${user.name}`);\n  });\n}\n\ngetUser()\n  .then((user) =&gt; getOrders(user))\n  .then((orders) =&gt; console.log(orders));\n<\/code><\/pre>\n\n\n\n<p><strong><em>Code Explanation:<\/em><\/strong><\/p>\n\n\n\n<ul>\n<li><code>getUser()<\/code> returns a promise that resolves with a user object.<\/li>\n\n\n\n<li>The first <code>.then()<\/code> receives that object as <code>user<\/code>.<\/li>\n\n\n\n<li>It passes <code>user<\/code> straight into <code>getOrders(user)<\/code>, which itself returns another promise.<\/li>\n\n\n\n<li>Since <code>.then()<\/code> automatically waits for whatever promise you return inside it, the second <code>.then()<\/code> doesn&#8217;t run until <code>getOrders()<\/code> resolves.<\/li>\n\n\n\n<li>That second <code>.then()<\/code> receives the resolved value as <code>orders<\/code>.<\/li>\n\n\n\n<li>The result is a flat, readable sequence instead of one function buried inside another.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Promise vs Callback in JavaScript<\/strong><\/h3>\n\n\n\n<p>A callback is just a function passed into another function to run later, and it was the original way JavaScript handled async code before promises existed. The problem shows up once you need multiple async steps in a row.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ Callback style\ngetUser(function (user) {\n  getOrders(user, function (orders) {\n    console.log(orders);\n  });\n});\n\n\/\/ Promise style\ngetUser()\n  .then((user) =&gt; getOrders(user))\n  .then((orders) =&gt; console.log(orders));\n<\/code><\/pre>\n\n\n\n<p><strong><em>Code Explanation:<\/em><\/strong><\/p>\n\n\n\n<ul>\n<li>In the callback version, each step is nested inside the previous one.<\/li>\n\n\n\n<li>As you add more steps, the code drifts further to the right; this is the &#8220;callback hell&#8221; problem.<\/li>\n\n\n\n<li>The promise version does the exact same job but keeps everything in a flat, linear structure.<\/li>\n\n\n\n<li>Errors are also easier to manage with promises, since one <code>.catch()<\/code> at the end can handle failures from any step in the chain.<\/li>\n\n\n\n<li>With callbacks, you&#8217;d need to add error checks inside every single one instead.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Async\/Await vs Promise in JavaScript<\/strong><\/h3>\n\n\n\n<p><code>async\/await<\/code> isn&#8217;t a replacement for promises; it&#8217;s built directly on top of them. <code>async<\/code> marks a function as one that returns a promise, and <code>await<\/code> pauses that function until the promise it&#8217;s waiting on settles.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>async function getOrderDetails() {\n  const user = await getUser();\n  const orders = await getOrders(user);\n  console.log(orders);\n}<\/code><\/pre>\n\n\n\n<p><strong><em>Code Explanation:<\/em><\/strong><\/p>\n\n\n\n<ul>\n<li><code>await getUser()<\/code> pauses execution inside <code>getOrderDetails()<\/code> until the <code>getUser()<\/code> promise resolves.<\/li>\n\n\n\n<li>Once resolved, that value is assigned directly to <code>user<\/code>, no <code>.then()<\/code> needed.<\/li>\n\n\n\n<li>The next line does the same thing with <code>getOrders(user)<\/code>.<\/li>\n\n\n\n<li>The result reads almost like regular, synchronous code, even though everything happening is still fully asynchronous behind the scenes.<\/li>\n\n\n\n<li>This is why most developers reach for <code>async\/await<\/code> over chained <code>.then()<\/code> calls once a sequence has more than one or two steps.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>5. How to Handle Errors in a Promise<\/strong><\/h3>\n\n\n\n<p>Errors in promises are handled with <code>.catch()<\/code> in chains, or <code>try\/catch<\/code> when you&#8217;re using <code>async\/await<\/code>. Skipping this step is one of the most common reasons apps crash silently or fail without explanation.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>async function getOrderDetails() {\n  try {\n    const user = await getUser();\n    const orders = await getOrders(user);\n    console.log(orders);\n  } catch (error) {\n    console.log(\"Something went wrong:\", error);\n  }\n}<\/code><\/pre>\n\n\n\n<p><strong><em>Code Explanation:<\/em><\/strong><\/p>\n\n\n\n<ul>\n<li>The <code>try<\/code> block runs the normal async logic, <code>await<\/code>ing each promise one after another.<\/li>\n\n\n\n<li>If either <code>getUser()<\/code> or <code>getOrders()<\/code> rejects at any point, execution immediately jumps to the <code>catch<\/code> block instead of continuing.<\/li>\n\n\n\n<li>The rejection reason gets passed in as <code>error<\/code>.<\/li>\n\n\n\n<li>This is the <code>async\/await<\/code> equivalent of chaining a single <code>.catch()<\/code> at the end of a <code>.then()<\/code> sequence.<\/li>\n\n\n\n<li>It gives you one place to handle failure no matter which step actually caused it.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Combining Multiple Promises in JavaScript<\/strong><\/h2>\n\n\n\n<p>Sometimes you&#8217;re dealing with several promises at once, like fetching data from three different APIs at the same time. JavaScript gives you four built-in methods for this, each handling multiple promises a little differently.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>1. Promise.all()<\/strong><\/h3>\n\n\n\n<p><code>Promise.all()<\/code> takes an array of promises and waits for all of them to resolve. If even one of them rejects, the whole thing rejects immediately, without waiting for the others to finish.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const p1 = Promise.resolve(\"User data\");\nconst p2 = Promise.resolve(\"Order data\");\nconst p3 = Promise.resolve(\"Payment data\");\n\nPromise.all(&#91;p1, p2, p3])\n  .then((results) =&gt; console.log(results))\n  .catch((error) =&gt; console.log(error));\n<\/code><\/pre>\n\n\n\n<p><strong><em>Code Explanation:<\/em><\/strong><\/p>\n\n\n\n<ul>\n<li><code>Promise.all()<\/code> receives an array containing <code>p1<\/code>, <code>p2<\/code>, and <code>p3<\/code>.<\/li>\n\n\n\n<li>It waits until every single promise in that array resolves.<\/li>\n\n\n\n<li>Once they&#8217;re all done, <code>.then()<\/code> receives <code>results<\/code> as an array, in the same order as the input, holding each resolved value.<\/li>\n\n\n\n<li>If any one of <code>p1<\/code>, <code>p2<\/code>, or <code>p3<\/code> had rejected instead, <code>.catch()<\/code> would run immediately with that rejection reason, and it would ignore the results from the other promises entirely.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>2. Promise.allSettled()<\/strong><\/h3>\n\n\n\n<p><code>Promise.allSettled()<\/code> also waits for every promise to finish, but unlike <code>Promise.all()<\/code>, it never short-circuits on a rejection. It gives you the outcome of every promise, whether it succeeded or failed.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const p1 = Promise.resolve(\"User data\");\nconst p2 = Promise.reject(\"Order failed\");\n\nPromise.allSettled(&#91;p1, p2]).then((results) =&gt; console.log(results));\n<\/code><\/pre>\n\n\n\n<p><strong><em>Code Explanation:<\/em><\/strong><\/p>\n\n\n\n<ul>\n<li><code>Promise.allSettled()<\/code> waits for both <code>p1<\/code> and <code>p2<\/code> to settle, regardless of outcome.<\/li>\n\n\n\n<li>The <code>results<\/code> array contains one object per promise, each with a <code>status<\/code> field set to either <code>\"fulfilled\"<\/code> or <code>\"rejected\"<\/code>.<\/li>\n\n\n\n<li>For <code>p1<\/code>, the object includes a <code>value<\/code> field holding <code>\"User data\"<\/code>.<\/li>\n\n\n\n<li>For <code>p2<\/code>, the object includes a <code>reason<\/code> field holding <code>\"Order failed\"<\/code>.<\/li>\n\n\n\n<li>Nothing gets skipped or thrown away, you get a full picture of every promise&#8217;s result.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>3. Promise.race()<\/strong><\/h3>\n\n\n\n<p><code>Promise.race()<\/code> doesn&#8217;t wait for every promise, it settles as soon as the first one settles, whether that&#8217;s a resolve or a reject.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const slow = new Promise((resolve) =&gt; setTimeout(() =&gt; resolve(\"Slow result\"), 2000));\nconst fast = new Promise((resolve) =&gt; setTimeout(() =&gt; resolve(\"Fast result\"), 500));\n\nPromise.race(&#91;slow, fast]).then((result) =&gt; console.log(result));<\/code><\/pre>\n\n\n\n<p><strong><em>Code Explanation:<\/em><\/strong><\/p>\n\n\n\n<ul>\n<li>Both <code>slow<\/code> and <code>fast<\/code> are set up to resolve after a delay, using <code>setTimeout<\/code>.<\/li>\n\n\n\n<li><code>slow<\/code> takes 2000ms, <code>fast<\/code> takes only 500ms.<\/li>\n\n\n\n<li><code>Promise.race()<\/code> doesn&#8217;t care about the rest; it settles the instant the first promise settles.<\/li>\n\n\n\n<li>Since <code>fast<\/code> finishes first, <code>.then()<\/code> receives <code>\"Fast result\"<\/code>, and whatever happens with <code>slow<\/code> afterwards is ignored.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h3 class=\"wp-block-heading\"><strong>4. Promise.any()<\/strong><\/h3>\n\n\n\n<p><code>Promise.any()<\/code> resolves as soon as the first promise fulfills, and it ignores rejections completely, unless every single promise rejects.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>const p1 = Promise.reject(\"Server 1 failed\");\nconst p2 = Promise.resolve(\"Server 2 responded\");\n\nPromise.any(&#91;p1, p2]).then((result) =&gt; console.log(result));<\/code><\/pre>\n\n\n\n<p><strong><em>Code Explanation:<\/em><\/strong><\/p>\n\n\n\n<ul>\n<li><code>p1<\/code> rejects and <code>p2<\/code> resolves.<\/li>\n\n\n\n<li><code>Promise.any()<\/code> ignores the rejection from <code>p1<\/code> completely.<\/li>\n\n\n\n<li>As soon as <code>p2<\/code> fulfills, <code>.then()<\/code> receives <code>\"Server 2 responded\"<\/code>.<\/li>\n\n\n\n<li>If every promise passed in had rejected instead, <code>Promise.any()<\/code> would reject too, with an <code>AggregateError<\/code> containing all the rejection reasons.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Common Promise Mistakes to Avoid<\/strong><\/h2>\n\n\n\n<p>Even developers who understand JavaScript promises well still trip over the same mistakes. Here are the ones that actually matter:<\/p>\n\n\n\n<ul>\n<li><strong>Forgetting to return a promise inside a chain<\/strong>: If you don&#8217;t return the promise from inside a <code>.then()<\/code>, the next <code>.then()<\/code> runs immediately instead of waiting, and you lose the whole point of chaining.<\/li>\n\n\n\n<li><strong>Not handling rejections at all<\/strong>: Skipping <code>.catch()<\/code> or a <code>try\/catch<\/code> means errors fail silently or crash your app with an unhandled rejection warning nobody notices until it becomes a production problem.<\/li>\n\n\n\n<li><strong>Nesting promises instead of chaining them<\/strong>: Wrapping a <code>.then()<\/code> inside another <code>.then()<\/code> recreates the exact callback hell promises were meant to fix.<\/li>\n\n\n\n<li><strong>Mixing async\/await with .then() in the same function<\/strong>: Bouncing between the two styles in one place makes the flow confusing and makes bugs harder to trace.<\/li>\n\n\n\n<li><strong>Using Promise.all() when one failure shouldn&#8217;t kill everything<\/strong>: If you actually need the result of every promise regardless of failures, <code>Promise.all()<\/code> is the wrong tool, <code>Promise.allSettled()<\/code> is.<\/li>\n<\/ul>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>Conclusion<\/strong><\/h2>\n\n\n\n<p>Working with a promise in JavaScript stops feeling confusing once you see it for what it is: a way to wait for something without stopping everything else. From creating one to chaining, combining multiple at once, or reaching for async\/await, it&#8217;s all built around that same simple idea. Once it clicks, async code in JavaScript just stops feeling like a fight.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><strong>FAQs<\/strong><\/h2>\n\n\n<div id=\"rank-math-faq\" class=\"rank-math-block\">\n<div class=\"rank-math-list \">\n<div id=\"faq-question-1788853712223\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">1. What is a promise in JavaScript?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>A promise in JavaScript is an object that represents the eventual result of an async operation, either resolved with a value or rejected with a reason.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1788853726028\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">2. What&#8217;s the difference between a promise and a callback in JavaScript?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>A callback is a function passed in to run later; a promise in JavaScript gives you a cleaner, chainable way to handle the same async flow without nesting functions inside each other.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1788853727567\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">3. Is async\/await better than using .then() with a promise in JavaScript?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Not better, just different. Async\/await reads more like synchronous code and is easier to follow when a promise chain has more than one or two steps.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1788853728420\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">4. What happens if you don&#8217;t handle a promise rejection in JavaScript?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>A promise in JavaScript that isn&#8217;t handled throws an unhandled rejection warning, and the error fails silently instead of being caught, which usually causes bugs that are hard to trace later.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1788853809317\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">5. When should I use Promise.allSettled() instead of Promise.all()?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>Use it when you need the outcome of every promise in JavaScript even if some fail, Promise.all() stops and rejects the moment one promise fails.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1788854096079\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">6. Can a promise in JavaScript be cancelled once it&#8217;s created?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>No, a promise in JavaScript cannot be cancelled or paused once it starts; it will always settle as either resolved or rejected.<\/p>\n\n<\/div>\n<\/div>\n<div id=\"faq-question-1788854096895\" class=\"rank-math-list-item\">\n<h3 class=\"rank-math-question \">7. Does a promise in JavaScript run synchronously or asynchronously?<\/h3>\n<div class=\"rank-math-answer \">\n\n<p>The executor function inside a promise in JavaScript runs synchronously, but <code>.then()<\/code>, <code>.catch()<\/code>, and <code>.finally()<\/code> always run asynchronously, even if the promise resolves instantly.<\/p>\n\n<\/div>\n<\/div>\n<\/div>\n<\/div>","protected":false},"excerpt":{"rendered":"<p>A promise in JavaScript is an object that stands in for a future value, which is either resolved (success) or rejected (failure). If you have ever written code that depends on data from an API, a file, or a timer, you have already run into the problem promises were built to solve. Before promises existed, [&hellip;]<\/p>\n","protected":false},"author":64,"featured_media":99212,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[429,907],"tags":[],"views":"1849","authorinfo":{"name":"Abhishek Pati","url":"https:\/\/www.guvi.in\/blog\/author\/abhishek-pati\/"},"thumbnailURL":"https:\/\/www.guvi.in\/blog\/wp-content\/uploads\/2026\/01\/promise-in-javascript-300x112.webp","_links":{"self":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/98755"}],"collection":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/users\/64"}],"replies":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/comments?post=98755"}],"version-history":[{"count":15,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/98755\/revisions"}],"predecessor-version":[{"id":137851,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/posts\/98755\/revisions\/137851"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media\/99212"}],"wp:attachment":[{"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/media?parent=98755"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/categories?post=98755"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.guvi.in\/blog\/wp-json\/wp\/v2\/tags?post=98755"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}