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 trialPablo Calvo
13,044 PointsGuys,... im having trouble understanding where does the "message" variable comes into play here... it is not defined...
where is the "message" defined..?
3 Answers
Steven Parker
231,275 PointsParameters are defined simply by naming them in the function definition:
function print(message) { // <-- this defines "message" as a parameter
Pablo Calvo
13,044 PointsThink I get it now Steven thanks for replying.
Steven Parker
231,275 PointsPablo Calvo — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!
Mikeal Mann
Full Stack JavaScript Techdegree Student 17,913 PointsHey Steven,
This is from w3school and it helped me understand it better:
The parameters, in a function call, are the function's arguments. JavaScript arguments are passed by value: The function only gets to know the values, not the argument's locations. If a function changes an argument's value, it does not change the parameter's original value. Changes to arguments are not visible (reflected) outside the function.
Basically, you can call the parameter whatever you desire. Just make sure that it makes sense to your future self when you come back to your code days later :) The variable could have been called text, message, sentence, cat etc.
Cheers, Mikey
Steven Parker
231,275 PointsThe part about "not changing the original value" only applies to primitive types. If an argument is an array, for example, the function can make permanent changes to the array contents that are visible outside the function.
anywayiam
3,970 Pointsanywayiam
3,970 PointsThe function print is actualy not nessesary. "function print(message) { document.write(message); }" You can use it to print or you can use document.write() method as well with out function.