I don't understand how the 'message' and 'list' parameters work
How does the function know what to put in for the value of the those parameters? Like 'message' isn't defined anywhere so how does it know what to display in document.write(message)? I'm just as confused with the 'list' parameter because I don't understand how it knows how long list.length is when it's not defined.
Yacine Diop3,465 Points
Think of this way:
- while writing the function, list is added as a parameter (I think of this as a placeholder); however, the intention for that space is for playlist later on.
- when we call the function to print, we now can place the var playList. This is our argument from the get go.
So while making the function, don't think list is not defined, instead the list will be defined later.
Same thing for document.write(message). Message is a placeholder, a parameter set into function print(message). We later called the function print(listHTML);
listHTML replaces the placeholder message.
This is how I think about it to make it clear to myself. Hope it helps someone.
Steven Parker194,522 Points
Parameters act as placeholders for the actual value that will be passed to the function when it is called.
You might think of a parameter as a variable that is declared by naming it in the function definition, and is automatically assigned when the function is called, getting set to the value supplied as the argument.
If a parameter is a list, the length of the list will be determined when the function is called and the real list is supplied as the argument.