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!

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 Basics (Retired) Creating Reusable Code with Functions Passing an Argument to a Function

Dayne Wright
Dayne Wright
11,235 Points

Why do you not need to create a parameter in a function with var?

I am curious as to why you do not need to create a variable first for the parameter you pass into a function. Is there a reason why it does not need it?

1 Answer

Jonathan Grieve
Jonathan Grieve
Treehouse Moderator 91,243 Points

I think it's because this challenge is asking you to create a variable in local scope. And that's what you're doing when you're passing in the parameter to the function returnValue. At the parameter stage, your first argument is a placeholder variable which is then given a value at function call.

function returnValue(one) {

   return one;

var echo = returnValue("My argument");

It's only when the function is called in the last line that JS knows what value to display in the "one" placeholder variable. :-)