1

In modern Javascript, we have something called Promises. We can use reject and resolve inside Promise.

My question is: do I need to return explicitly after calling reject or resolve inside Promise? So something like this:

function foo() {
  ...
  return new Promise((resolve, reject) => {
    ...
    if (err) {
      reject(err);
      // return;
    }

    if (httpResponse.statusCode === 200) {
      resolve(httpResponse);
      // return;
    }
  });
}
elquimista
  • 2,181
  • 2
  • 23
  • 32

1 Answers1

-2

My question is: do I need to return explicitly after calling reject or resolve inside Promise? So something like this:

No, you don't need a return statement.

From Mozilla Developer Network's Promises article:

Syntax

new Promise( /* executor */ function(resolve, reject) { ... } );

As you can see, no mention of any return statements.

Rob Axelsen
  • 844
  • 6
  • 8
  • Whilst this may theoretically answer the question, [it would be preferable](http://meta.stackoverflow.com/q/8259) to include the essential parts of the answer here, and provide the link for reference. – Heretic Monkey Mar 02 '17 at 20:15
  • Thanks. I am new to this site. Will update answer. – Rob Axelsen Mar 02 '17 at 20:17