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

Functions

Trying to follow along with intro to programming. In this function,

var debug = function(message) {
    console.log("Debug",message);
}
var x = 1;
debug("x has been set");

what does the "message" fit in?

4 Answers

Hey Douglas,

The "message" part of your function is the known as the parameter. Example:

functionName(parameter1, parameter2, parameter3) { code to be executed; }

They are the "names" to be used by the function as formal argument names and will let you reference whatever data that is passed by that name. In the example you gave us, you can see that the "message" name in two places of the function: once in the parameter:

 var debug = function(message) ... // <--- Here

and once in the body of the function

 console.log("Debug",message); ... // <--- Here

When you "called" the function, you gave the function an argument that will act in place of the named parameter:

  debug("x has been set"); // <-- here

So the string "x has been set" will now act as the argument and be passed into the function parameter "message", where you can reference "x has been set" as the parameter "message."

You asked where does the "message" fit in, well if you execute and call your function, debug("x has been set"), the string "x has been set" will act as the argument, take the place of the parameter "message", be passed into function body where the message variable appears, including console.log(message), which will execute as

 console.log("debug", "x has been set")

and you should see "Debug, x has been set" in your console as a result of the call of all the preceding functions(debug(), console.log() etc.).

Hope this helps!

message is a parameter to the debug function.

When you call the function, you can add parameters to it, and then the function does something with those parameters. In this case, whatever is passed to the debug function is printed in the console.

in the function definition below

var debug = function(message) {
    console.log("Debug",message);
}

message is a parameter. when the function is called, the user passes an argument to it. that argument is basically stored in the message parameter, and the function uses that message variable in the body of the function.

Thanks to all , now i understand, the Parameter is like a variable, that makes sense!