# Functions' Arguments

Functions' arguments are the values passed to parameters when calling or invoking a function. This is a page on it own because most of the time, beginners confuse parameters and arguments for same thing. But then, the difference is clear. Parameters are variables declared on a function parentheses (()) which can be used in the function as their values will be assigned when calling the function. Arguments on the other hand are the real values passed or assigned to those parameters when calling the function. In another view, parameters can be seen as declared variables while arguments are the values assigned to those parameters or variables.
``````function addNum(x, y){
//x is the first parameter
//y is the second parameter
}

addNum(2, 10); //2 is the argument or value to the first parameter
//10 is the argument or value to the second parameter``````
In simpler terms, an argument is a value to a function parameter. A FUNCTION CAN HAVE MORE PARAMETERS THAN ARGUMENTS AND VICE VERSA A function can have up to six(6) parameters when defined and less arguments when called. This is not allow in some strict programming languages like PHP and JAVA but JavaScript permits such.
``````//DEFINING FUNCTION
function myFunc(a, b, c, d, e, f){
}
//CALLING FUNCTION
myFunc(1, 2, 3); //THREE ARGUMENTS
myFunc(3); //ONE ARGUMENT``````
What happens: Remember variables without values are undefined. So, when we don't pass some arguments for some parameters, the value of those parameters becomes undefined.
``````<script>
function myFunc(x, y){
}

myFunc(34); //Argument for x but none for y, so y is undefined
</script>``````
Therefore, ensure you pass arguments to all parameters that your function depends on else it won't execute or execute properly.
``````<script>
var sum = x + y; //the function needs x and y to function properly
}

</script>``````
Also, functions in JavaScript can have more arguments than the parameters.
``````function myFunc(x,y){
}
myFunc(1, 2, 3);
myFunc(3, 9, 0, 59)``````
The implication is that you can't access all arguments because there was no variable in the function parentheses to hold or name them but there is a way around this. The JavaScript functions' arguments object. You will learn about the argument object in the next page.
NOTE:
• Functions' arguments can be values of any data type be it numbers, strings, booleans, arrays, objects and function. A particular parameter can have separate data type at various points of invocation.
``````alert(1); //argument is a number
alert([1, 2, 3]); //argument is an array
So, you can see one parameter having different data types as arguments when invoked.
SUMMARY
1. After declaring parameters when defining a function, the values we assign to those parameters are known as arguments .
2. In JavaScript, it is allowed for functions to have more parameters and when calling them, we pass less arguments. The implication is that the value for parameters without arguments will be undefined.
3. It is important you pass arguments to all parameters your function depends on for its execution or proper execution.
4. It is also allowed for a function to have more arguments than declared parameters. This also means that a function without parameters can be assigned arguments. The implication is that you won't be able to access such arguments.
5. If a function have more arguments than parameters, you can access all the arguments using the function argument object.
Take a short quiz on Functions' Arguments.
Ask a question or tell us if Functions' Arguments is easy or not.
cent?