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 JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Using For Loops with Arrays

Carissa Thomas
Carissa Thomas
2,715 Points

Confused as to where the list parameter comes from. I thought parameters were defined by the caller of the function?

Yeah, where does the list parameter come from?

2 Answers

Darrell Conklin
seal-mask
.a{fill-rule:evenodd;}techdegree
Darrell Conklin
Python Development Techdegree Student 22,377 Points

"list" is simply a placeholder description of the parameter that will passed to the function and will be replaced with the parameter passed to it.

Arikaturika Tumojenko
Arikaturika Tumojenko
8,897 Points

How can you use a placeholder before you defined it? As far as understand, the list array didn't exist when we started to write the function, it only existed after the loop ran.

Oliver Duncan
Oliver Duncan
16,642 Points

Arikaturika: the playlist array was already defined and passed as an argument to the printPlayList function. This function used the values within the playlist array to generate an ordered list in HTML, and print it to the page.

The 'placeholder' or argument to a function doesn't have to be defined before using it, which is what makes functions so useful: you can use them more than once using different arguments, making your code more efficient and easier to read. In this case, you could print as many different lists as you wanted just by calling the same function and passing it different arguments each time.

Cindy Lea
PLUS
Cindy Lea
Courses Plus Student 6,497 Points

The caller function provides the values for the function & the function itself has parameters that it uses within the function