Chained native promises...promise h*ll!

Hi
Could somebody please explain why in the code below firstValue from the first promise is passed into the second promise function returnsSecondPromise() as an argument? Is firstValue not just some resolved value like 'Yay I resolved!'? Why/how does the second promise in the chain need/use this resolved value?

Thank you!

Code:

function nativePromiseVersion() {
    returnsFirstPromise()
    .then((firstValue) => {
        console.log(firstValue);
        return returnsSecondPromise(firstValue);
    })
   .then((secondValue) => {
        console.log(secondValue);
    });
}

That firstValue could be a simple string, but it also could be something much more complex like an object representing the user after the first promise looked it up in a database. The next parts of the chain may need that to process whatever it is that they do. Like validating information, processing a payment, adding more information to it, and passing it down the chain.

Edit: By the way, I know this can be very confusing. I think once you get into some practical applications of these concepts in future lessons, a lot of the haziness will start to fade away. For example, when you get to using fetch to get data from the internet, you’ll see things come together.

1 Like

Yeah it’s been a bit confusing. I’m a big fan of Codecademy but don’t think this is a module they’ve explained well (for me personally anyway). I have had to do a lot of study away from the site (which i understand will eventually be what a coder does for a living! lol) to grasp it. Still a few more chapters in the module though so perhaps i’m jumping the gun a bit.

Thanks for your help again.

1 Like