arguments function scope variableS2C Home « Statements « arguments

Array-like object.

Description

The arguments object is a function scope variable that holds a list of the arguments passed to the function.

  • The arguments object is only available within a function and will return an error if used outside the function body.
  • The arguments object can be accessd in the same way as an array but no array like-methods are avaialable to it except length.
  • The arguments object can be be modfied using a zero based index.

Syntax


Signature Description
arguments[argsInd]The arguments object is a function scope variable that holds a list of the arguments passed to the function.

Parameters


Parameter Description
argsIndOptional zero based index for argument retrieval/modification.

Examples

The code below gives examples of using the arguments statement.


*/
 / Create a function statement that takes an argument,
 / modifes the argument within the function and 
 / returns the square of the modified argument.
 /*
function squareNumber(a) {
  alert(arguments[0] + ' argument before modification';)
  alert(arguments.length + ' number of arguments';)
  arguments[0] *= 2;
  alert(arguments[0] + ' argument after modification';)
  return a * a;
}
alert(squareNumber(5));
alert(squareNumber(10));

Press the button below to action the above code:


Related Tutorials

JavaScript Intermediate Tutorials - Lesson 8 - Functions

go to home page Homepage go to top of page Top