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 JavaScript and the DOM (Retiring) Responding to User Interaction Functions as Parameters

Ryan Schmelter
Ryan Schmelter
9,710 Points

Do func and arg have meaning themselves?

The way he's wording this makes it seem like func and arg are actually part of JavaScript syntax. Is that the case or can these be named anything here?

2 Answers

Hi Elizabeth,

Although it's been a while since you asked this question I figured I'd post an answer for anyone else struggling.

The JS program starts by defining the say function. When say runs, it logs whatever argument you pass through it to the console.

When the exec function runs, it expects the first parameter passed to be a function and the second parameter to be an argument that will be passed into that function. Take a look at the function declaration in the exec function. Running exec(say, 'hi there'); calls the say function then passes 'hi there' into the parameter of the function. In other words the () is there, only within the function.

This is my first forum response and I'm not sure it makes sense, but I hope it helps clear it up haha.

Ezra Siton
Ezra Siton
12,644 Points

No. You can use any name. This is only for the semantic (give meaning to vars, functions names) - you can change "func" to "abcde" and "arg" to "wow" or any name you want.

Besides Reserved Words:

In JavaScript you cannot use these reserved words as variables, labels, or function names (3WC)

Elizabeth Chai
Elizabeth Chai
9,692 Points

Sorry, I am confused. How can he call the function say without adding the () behind it? like shouldn't it be: exec(say(), "Hi There")? Because otherwise wouldn't the results end up as say(Hi There) which doesn't make sense unless browser knows that say is a function? Sorry if i don't make sense...

For Elizabeth: "say" isn't being called there, it's being passed as an argument to another function, as if it were a number, string, or any other data type. "say()" calls the function, "say" passes it as an argument.