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 Introducing the Practice

Leslie Lello
seal-mask
.a{fill-rule:evenodd;}techdegree
Leslie Lello
Front End Web Development Techdegree Student 8,297 Points

This is something that has always messed me up with JavaScript: passing an undefined value to a function

When you pass a value to a function, as in this video with the word 'list', how does JavaScript know what the value of list is?

It was never defined.

So how does it know what list.length is?

This is something I have struggled with for years and I have never received a clear answer. I hope you can answer this clearly. Thanks.

1 Answer

It is an argument. u can pass parameters into fucntion, condiser this example: lets say i have a variable called name

//declare a variable to store the string "idan";
const name = "idan";

//this is a function that get some argument, we will pass the "name" variable into it 
function sayHello(someName) {
  console.log("my name is " + someName);
}
//no we call the function and pass "name" into the sayHello function, notice that "sayHello" fucntion exepect an argument called "someName".
//but what u need to under is we can call the argument in whatever name we want, the argument "someName" it's just a placeholder for the "name" variable.
//your actually passing "name" into the sayHello fucntion.
sayHello(name);

sayHello()

}

run this code and ull see the output:

my name is idan

if u won't pass any argument, then the output will be:

my name is undefined
``