Search code examples
javascriptes6-promise

.then is not a function


Why is this line a valid promise:

const promise = Promise.resolve('Hello');

But not this:

const otherPromise = () => {
  return Promise.resolve('Hello');
}

When trying to call the second example with:

function runOtherPromise() {
  otherPromise
    .then(v => console.log(v));
}

...I get TypeError: otherPromise.then is not a function. It works fine with the first example, though. I don't understand why the second example doesn't return a promise.


Solution

  • otherPromise is a function, you should call it like below:

    runOtherPromise() {
        otherPromise()
            .then(v => console.log(v));
    }