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 trialDaniel Stewart
3,163 PointsReference enquiry
Hello,
Just quick question.
When he declares the function with the argument (list) is this directly referencing the list array? How is this linked when passing an array into a function?
I know with objects you must use properties from the object to link it to the function like if you wanted update the value of a property with a function.
Thanks, Daniel
2 Answers
nick black
5,578 PointsWhen he declares the function with the argument (list) is this directly referencing the list array? How is this linked when passing an array into a function?
It is directly referencing the list array. Since JavaScript doesn't require datatypes in these variable declarations, I think it can be a little confusing to know what is specifically being referenced. I think this is the difference in a loosely typed language vs. strict type, but that isn't important here.
What is important, is knowing that an array with the name list is being referenced as the parameter in this function and so when you pass an argument to the function, it is going to be of an array type. That said, the way this is actually handled by the language is probably using pointers so the array list is actually a place in memory and JavaScript creates an object that points to the memory address that contains the array and that way it isn't passing around the array itself over and over and wasting resources.
Maybe I'm over complicating this, but it seems like you have experience with this concept anyway and that's what you were referencing from your object oriented knowledge.
Cheers!
Steven Parker
231,275 PointsWhen you declare a function, you don't know what arguments will be given. Your declaration includes parameter names that act as placeholders for the actual arguments that will be supplied in the call.
In this video, when the function is called, the argument given is "playList". So that is what "list" represents when the function runs.