frozen
frozen

Reputation: 2154

What to do when there's nothing to return in a promise?

When I have a promise, I usually do something like:

funcPromise()
.then(()=> {
    // some stuff happens
    return value; // what if there's nothing to return here?
})
.then(()=> { //... 
})
.catch(err=>log(err));

But if there's nothing to return, should i do return Promise.resolve() or return null, or simply return;?? I know that in a one-liner, the arrow function has implicit return, but for my case, it's a multi-statement function.

Upvotes: 10

Views: 7048

Answers (2)

Animatry
Animatry

Reputation: 79

The promise actually returns an object that has a value if you call the right method. Maybe that helps?

Upvotes: 1

SLaks
SLaks

Reputation: 887767

It doesn't matter.

If you have no return statement (or a return statement with no value), the function will return undefined, resulting in a promise of undefined.

That is presumably fine for you.

Upvotes: 10

Related Questions