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 Create an Array of Objects

Cant understand parameters passed to a function

I have trouble understanding parameters in functions. If we have name of array products why parameter prod?

1 Answer

Hi Julia,

First off, itโ€™s important to know that arguments and parameters arenโ€™t the same thing. It can be confusing and a bit difficult to distinguish between the two because they are so closely related, but they are not the same thing.

I want to point that out because parameters are not passed into functions, arguments are. Parameters are more like placeholders used to represent something else (something undetermined) in function definitions. Arguments are the actual values that are then passed into a function and take the place of the placeholders.

prod is just the name used to represent the argument/value that will later be passed in. You could change all references to prod to something like beeswax (which would be a nonsensical parameter/variable name), but the code would work the exact same way. The computer doesnโ€™t care what you call it. But when a human reads the code, the variable/parameter prod would be immediately recognizable as a description for the type of data the variable/parameter will store.

So when the function is called, the human knows that a product should be passed into the function as an argument. Or in this case, an array of objects is passed into the function (perhaps prods would be a better variable name in this case).

Hopefully, that answers your question. If not, let me know and Iโ€™ll try again.

Thank you