JavaScript Arguments Object Function Tutorial
In this exercise we explore the Arguments object in JavaScript. Which enables us to create special functions that can intake an undetermined amount of arguments. All of the functions we write, have an arguments object tied to them that we can access.
Access function arguments using their index position.function doSomething() {
alert( arguments[0]+" "+arguments[1] );
}
doSomething("Hello", "World");
Access function arguments through iteration with a loop.
function sum() {
var result = 0;
for( i = 0; i < arguments.length; i++ ){
result += arguments[i];
}
return result;
}
alert( sum(10, 5, 2, 3, 10) );