JavaScript JavaScript Loops, Arrays and Objects Tracking Multiple Items with Arrays Using For Loops with Arrays

Pablo Calvo
Pablo Calvo
1,144 Points

Guys,... 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
Steven Parker
182,590 Points

Parameters are defined simply by naming them in the function definition:

function print(message) {  // <-- this defines "message" as a parameter
Pablo Calvo
Pablo Calvo
1,144 Points

Think I get it now Steven thanks for replying.

Steven Parker
Steven Parker
182,590 Points

Pablo Calvo — Glad to help. You can mark a question solved by choosing a "best answer".
And happy coding!

Mikeal Mann
Mikeal Mann
Full Stack JavaScript Techdegree Student 9,067 Points

Hey 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
Steven Parker
182,590 Points

The 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.