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

Usman Shahid
Usman Shahid
13,554 Points

'list' inside the function parameter holds an array 'playList'. But how and where?

Inside the 'function' Dave explains:

function printList ( 'list') { ... }

'list' is holding array value. How it is doing that?

2 Answers

Valeshan Naidoo
Valeshan Naidoo
27,008 Points

The function takes one argument, which is 'list'. 'list' is basically like a placeholder. Within the function, there is a for statement that loops through the list and appends it to the ol element.

After the function is written, David calls the function and puts in the variable playList as the argument, so it goes through what the 'list' argument in the function would go through. Therefore the function will loop through the contents of the playList and add them into an ol element.

Usman Shahid
Usman Shahid
13,554 Points

Now I get it. This means I could have any array and whenever I pass an array to the function printList, it will print it.

Thank you for clearing the concept.

Super helpful explanation because the placeholder idea is confusing as it is abstract, not tied to a specific value in the code. Thank you for making this clear.