JavaScript Asynchronous Programming with JavaScript Understanding Promises From Callbacks to Promises

Takuya Hirata
Takuya Hirata
23,293 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,293 Points

Thanks Steven! Happy coding!

1 Answer

Steven Parker
Steven Parker
201,932 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,293 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
201,932 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!