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

Michael Rushton
Michael Rushton
7,126 Points

Why do we pass the function the parameter (data) and not (data.message) - why do we pass a parameter at all?

For some reason i can't find the option to post this question on the relevant page i am stuck on, so it keeps putting it as a global javaScript question. the page i'm trying but failing to post on is....

https://teamtreehouse.com/library/displaying-the-content#questions

Im really struggling to understand why after saying that the fulfilled promise from the second .then (response.json) is going to be called data and then use an arrow function to create a function that has arguments (data.message) but then when we go to actually say what that function will do (below) why do we only put (data) as the argument? not (data.message). i don't understand why we put (data) in the generateImage function or any parameter as id have thought when the function is called by the .then part it would populate the function with the appropriate (data.message) arguments in order to locate the correct part of the returned json. It's been driving me crazy since last night. Please someone help my poor brain!!😂😂

2 Answers

Steven Parker
Steven Parker
231,248 Points

Remember that parameter names are simply placeholders and have no meaning themselves. So even though the parameter name is data, the argument passed in the call is data.message, so that is what the parameter will contain when the function runs.

It might have made more sense to name the parameter message instead of data, but simply for clarity when reading the code. It would not affect the operation.

Steven Parker
Steven Parker
231,248 Points

You're right, the name is like a label. You can call a parameter anything you want, but a "best practice" is to choose a name that represents the kind of data that will be passed in.

Michael Rushton
Michael Rushton
7,126 Points

Thanks so much for your help. I have almost got my head around it I think. So the reason you put a parameter on a function is to basically label what kind of input it will expect in order to carry out the code within? Whatever is written in the parenthesis at the initial declaration doesn't really matter as far as executable code? Am i right? lol. Thanks so much for your patience.