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 Introduction to Programming Functions Functions

Functions

I am really struggling to understand arguments in functions. Is there any more resources on this to help as I have watched the video multiple times and are still failing to understand?

1 Answer

Stone Preston
Stone Preston
42,016 Points

arguments allow variables to be passed to the function and manipulated inside it. so you could create a function that adds 2 numbers together. 2 variables could be passed to the function as arguments, and then added together inside the function block and returned. so I could write

function addTwoNumbers(number1, number2)
{
  return number1 + number2;
}

In the case of a function definition, the variables inside the ( ) are referred to as parameters. They are only referred to as arguments when you use the function or call it. So above they are parameters, but below the numbers in the ( ) are arguments:

var sum = addTwo( 1,5 );