Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trial![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Jesus Olaiz](https://secure.gravatar.com/avatar/9a114b6e7682f5d337a293fcf0479d0b?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Jesus Olaiz
9,210 PointsIm confused on how the callbacks are working here
const myPromise = new Promise( (resolve, reject) => {
setTimeout(() => {
resolve(7);
}, 1000);
});
console.log(myPromise);
myPromise
.then(a => a+5 )
.then(b => b*6)
.then( val => console.log(`You got ${val}`))
I know how to make it work, but there is something about the logic that has been just making me go kind of crazy.
myPromise
.then(a => a+5 )
Written out in a pyramid of doom I can still follow the code pretty well and make sense of how the function is getting the result of the next, but here I just cant make sense as to how the engine knows that the result applies to the variable or parameter a
. Like I said, I can make a promise work but I would love a bit more in depth explanation of what is happening here so I don't feel like I'm just guessing the whole time and some how getting lucky.
Thanks in advance!
1 Answer
![Steven Parker](https://uploads.teamtreehouse.com/production/profile-photos/969492/micro_tool_chess_set_2.jpg)
Steven Parker
230,688 PointsWhat you're seeing is just the nature of .then. The callback function you pass to it has one argument, the fulfillment value. When the callback is invoked, then passes that value to the function.
You might want to take a look at the MDN page on .then.