ilovebigmacs
ilovebigmacs

Reputation: 993

.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.

Upvotes: 2

Views: 9657

Answers (1)

Faly
Faly

Reputation: 13356

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

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

Upvotes: 6

Related Questions