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

JavaScript Asynchronous Programming with JavaScript Understanding Promises From Callbacks to Promises

Takuya Hirata
Takuya Hirata
23,296 Points

getProfiles without a parameter?

Please somebody explain why the getProfiles function can be called even though the function is called without a parameter?

Takuya Hirata
Takuya Hirata
23,296 Points

Thanks Steven! Happy coding!

1 Answer

Steven Parker
Steven Parker
231,268 Points

The "then" method takes up to two arguments, both callback functions. The first function is called on successful resolution, at which time it is passed the fulfillment value from the promise. So it does get a parameter when it is called (it is not being called at the spot where "then" is being used).

For more details, see the MDN page on "then".

Takuya Hirata
Takuya Hirata
23,296 Points

Thanks Steven,

I'm not too sure that the getProfiles function was declared like "function getProfiles(json){}", so I thought the getPfofiles function would need to take a parameter when it's called like getProfiles(something: value form pormise).

Thanks!

Steven Parker
Steven Parker
231,268 Points

That's exactly how it gets called. You don't specify the argument when you pass the callback to "then", but when it gets called, "then" will supply the argument.

Happy coding!