'What is different this return of promise? [closed]

What is different promise here

promise()
.then(
   otherPromise()
)
.catch(error)

and here :

promise()
.then(() => {
   otherPromise()
})
.catch(error)

Someone can help me with explain it



Solution 1:[1]

In the first example, you're passing the return value of calling otherPromise() to your then. In the second example you're passing a function which will call otherPromise() when the then is reached.

For example, lets assume otherPromise() just returns a string like this:

const otherPromise = () => 'Hello World';

In the first example you are passing the string 'Hello World' into your then, in the second you are passing a function in.

I suspect what you want to do is this:

promise()
  .then(otherPromise)
  .catch(error)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 ollie