Search code examples
javascriptnode.jsecmascript-6promisees6-promise

Difference between these 2 promises syntax


I am quite confused between these two ways of returning the promises, could someone please explain the difference? I tried to find some whereabouts on google, but couldn't find the exact match.

var a = Promise.resolve('foo');
return a.then();

vs

return Promise.resolve('foo').then();

Solution

  • There's nothing promise specific about this.

    return a.b();
    

    Is the same as:

    var c = a;
    return c.b();
    

    In this case a is Promise.resolve('foo').