---
title: "Discussion on \"6 Common mistakes in using JavaScript Promises\" | Hashnode"
description: "Discussion on \"6 Common mistakes in using JavaScript Promises\". As beginners of JavaScript Promises, you may make a few common mistakes. This article to help you identify them and start using them in the right way."
url: "https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580"
---

[Feed](https://hashnode.com/feed) /

Discussion

# [6 Common mistakes in using JavaScript Promises](https://blog.greenroots.info/common-mistakes-in-using-javascript-promises?utm_source=hashnode&utm_medium=feed)

As beginners of JavaScript Promises, you may make a few common mistakes. This article to help you identify them and start using them in the right way.

Sep 20, 2021 · 8 min read · blog.greenroots.info  
Updated Dec 15, 2021  
Read the article

-   [#javascript](https://hashnode.com/tag/javascript)
-   [#codenewbies](https://hashnode.com/tag/codenewbies)
-   [#nodejs](https://hashnode.com/tag/nodejs)
-   [#beginners](https://hashnode.com/tag/beginners)

## Written by

[Tapas Adhikary](https://hashnode.com/@atapas)

@atapas · Bangalore

  
[View profile](https://hashnode.com/@atapas)

Educator @tapaScript | Founder CreoWis & ReactPlay - Writer - YouTuber - Open Source

Co-Founder, @CreoWis | Teacher, @tapaScript | Founder, @ReactPlay | YouTuber | Writer | Human

## Responses 8

Markdown supported · ⌘↵ to post

[Alex Kit](https://hashnode.com/@tenbits)

[Dec 23, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/61c4a3ea1b569f3d7b388852)

For such things like loops, filters, groups I use [alot](https://github.com/atmajs/alot) library - it designed for lazy iterations over arrays, but also supports `Promise` handlers. The first example would look like this:

```
const names = ['saviomartin', 'victoria-lo'];
const users = await alot(names)
    .mapAsync(async name => {
        let { data: user } = await axios.get(`api.github.com/users${name}`);
        return user;
    })
    .toArrayAsync({ threads: 4 })
```

[Tapas Adhikary](https://hashnode.com/@atapas)

[Dec 23, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/61c4a3ea1b569f3d7b388852#reply-61c4a5a10e66663d56fcc00a)

[Alex Kit](https://hashnode.com/@tenbits), Great, thanks for letting me know. Shall explore it.

[Usman Sabuwala](https://hashnode.com/@usmanwrites)

[Sep 26, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/61502be07ef2d57e218f0759)

This is a superb topic which very few people talk about! You made this so easy to understand!

[Tapas Adhikary](https://hashnode.com/@atapas)

[Sep 27, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/61502be07ef2d57e218f0759#reply-615143d294bb297e1aad92ab)

Thank you [Usman Sabuwala](https://hashnode.com/@usmanwrites)

[Pierre-Henry Soria](https://hashnode.com/@ph7)

[Sep 26, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/614fc39c94bb297e1aad76fb)

Amazing article! 🎉 Thank you so much for sharing this with us ☺️

[Tapas Adhikary](https://hashnode.com/@atapas)

[Sep 27, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/614fc39c94bb297e1aad76fb#reply-615143bd9b404a3239699c1b)

Thanks a lot [Pierre-Henry Soria](https://hashnode.com/@ph7)

[Eleftheria Batsou](https://hashnode.com/@eleftheriabatsou)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/6149c74a20bcc6765ac04ac2)

I think you are the king of JS promises 😎!

[Tapas Adhikary](https://hashnode.com/@atapas)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/6149c74a20bcc6765ac04ac2#reply-6149cba420bcc6765ac04b54)

[Eleftheria Batsou](https://hashnode.com/@eleftheriabatsou) Hehe...Thanks a lot for thinking that way 😂!

I am sure of eating, drinking, sleeping with promises for a month now. Time to build another kingdom 😀.

[Tadit Dash](https://hashnode.com/@taditdash)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/614991a417da986cea64926e)

Great article Tapas. Just saw one typo.

`.ctach()`

You can search and correct.

Thanks,

Tadit

[Tadit Dash](https://hashnode.com/@taditdash)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/614991a417da986cea64926e#reply-614993ffcb77f11a64ce4e6b)

[Tapas Adhikary](https://hashnode.com/@atapas) one more is there too.

Conclusion: Always use .ctach()...

I Promised to Catch all typos. 😂😂

[Tapas Adhikary](https://hashnode.com/@atapas)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/614991a417da986cea64926e#reply-6149cacb699fe76cd3486473)

[Tadit Dash](https://hashnode.com/@taditdash) Oye.. I do not find amymore.. haha.. it shows 3 in our earlier conversation...

![image.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1632225960519/dwBnxlIAA.png)

Make sure of not a false promise(cached)

[Tadit Dash](https://hashnode.com/@taditdash)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/614991a417da986cea64926e#reply-614a3e0d20bcc6765ac05a0c)

[Tapas Adhikary](https://hashnode.com/@atapas) it was cached. 😎🙏

[Ankur Tyagi](https://hashnode.com/@TheAnkurTyagi)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/614980e617da986cea649074)

Great post [Tapas Adhikary](https://hashnode.com/@atapas)

[Tapas Adhikary](https://hashnode.com/@atapas)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/614980e617da986cea649074#reply-6149901c17da986cea64920a)

Thanks a lot [Ankur Tyagi](https://hashnode.com/@TheAnkurTyagi)

[M. Suman Patra](https://hashnode.com/@msuman)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/6149707517da986cea648e81)

**Really Nice article !!**

I will take this opportunity to clear my doubts. I code as per below.

```
const request = require('request');
const test = userData => {
  console.log('test::parameters', userData);
  if (userData && userData.request === true) {
    const option = {
      method: 'POST',
      url: 'jsonplaceholder.typicode.com/posts&,
      headers: {
        'Content-type': 'application/json; charset=UTF-8'
      },
      json: true,
      proxy: null,
      body: {
        title: 'foo',
        body: 'bar',
        userId: 1
      }
    };
    console.log('test::outgoingBody::', option);
    return new Promise((resolve, reject) => {
      request(option, (error, response) => {
        if (error) {
          return reject(error);
        } else {
          if (response && response.body ) {
            return resolve();
          } else {
            return reject(new Error('Error Response'));
          }
        }
      });
    });
  } else {
    return Promise.reject(new Error('Invalid Userdata'));
  }
};
//some business logics
test().catch(err=>console.error(err))
//some business logics
//--------------------------
//some business logics
test({request:true}).catch(err=>console.error(err))
//some business logics
```

1.  As I am not returning anything from test function, I don't use then callback.
2.  I use Promise.reject to throw any synchronous error.

Am I doing correctly?

[M. Suman Patra](https://hashnode.com/@msuman)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/6149707517da986cea648e81#reply-6149893617da986cea649165)

[Tapas Adhikary](https://hashnode.com/@atapas), To catch test function errors gracefully, I am using catch callback but I thought then callback is not needed because I am not waiting for test function execution and also not returning anything from API call/from the test function.

Note: As the request dependency does not support async/await, I had to use promise constructor.

[Tapas Adhikary](https://hashnode.com/@atapas)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/6149707517da986cea648e81#reply-61499129699fe76cd3485c6f)

[M. Suman Patra](https://hashnode.com/@msuman), I get that. In your typical case, where you do not return anything by resolving the promise, you are not accountable for handling it.

```
if (response && response.body ) {
     return resolve();
}
```

So, the current handling works to take care of the error test cases alone. If that's what is the intention, it looks good to me.

[M. Suman Patra](https://hashnode.com/@msuman)

[Sep 21, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/6149707517da986cea648e81#reply-614991c817da986cea64927a)

[Tapas Adhikary](https://hashnode.com/@atapas), Thanks for the info and will be waiting for ur next youtube video.

[Trang Le](https://hashnode.com/@bytrangle)

[Sep 20, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/61488f9717da986cea647c96)

Great article. I'm embarrassed to admit that I've committed all of the mistakes above, despite the number of times I re-read about promises.

Regarding handling errors within promises, do you think it is essential that web apps display error messages in UI? I think just `console.log` them is not very helpful.

[Tapas Adhikary](https://hashnode.com/@atapas)

[Sep 20, 2021](https://hashnode.com/posts/common-mistakes-in-using-javascript-promises/61486c2e699fe76cd3484580/comment/61488f9717da986cea647c96#reply-6148933a699fe76cd3484969)

[Trang Le](https://hashnode.com/@bytrangle), I think most of us do many of these :)

About your suggestion of propagating the errors to the UI, absolutely. In real-life examples, that's how it should be.
