Chaining multiple promises

Hello everyone,

I am wondering why do we use the return link(true) at the bottom of the chaining promises ?

Do we return it so that he ban be used as an input in the next .then() statement or what ?

Hi there!

Yes, pretty much.

The .then() method takes up to two arguments, like so:

obj.then(onFulfilled, onRejected)

In your example, you have this code:

.then(data => {
    console.log(data + " 1");
    return link(true);

What’s happening here is we’re calling .then(), and providing it with a single argument - the callback function for onFulfilled. (The callback function for onRejected is optional.)

In this case, the callback function returns a value (link(true)) and so the promise returned by the .then() method gets resolved and the value of the promise is the return value from the callback.

The value of the fulfilled promise from .then() can be passed on down the chain to the next .then().

There is some more information about .then() and how it works here, in the Mozilla dev docs.