ECMAScript arguments object

Function object arguments object
In the functional code, using a special object called arguments, developers can access arguments without explicitly specifying their names.
For example, in the function sayHi(), the first argument is message. This value is also accessible with arguments[0], which is the value of the first argument (the first argument is at position 0, the second argument is at position 1, and so on).
Thus, we can override the function without explicitly naming parameters:

function sayHi() {
  if (arguments[0] == "bye") { return; } alert(arguments[0]); }

Number of test parameters
You can also use the arguments object to detect the number of arguments to a function by referring to the arguments.length property.
The following code prints the number of arguments used per call to the function:

function howManyArgs() {
  alert(arguments.length);
}

howManyArgs("string", 45);
howManyArgs();
howManyArgs(12);

The above code displays “2”, “0”, and “1” in turn.
Note: Unlike other programming languages, ECMAScript does not verify that the number of arguments passed to a function is equal to the number of arguments defined by the function. A developer-defined function can take any number of arguments (up to 255, according to Netscape documentation) without throwing any errors. Any missing arguments are passed to the function as undefined, and extra functions are ignored.
Analog function overloading
To simulate function overloading, use the arguments object to determine the number of arguments passed to the function:

function doAdd() {
  if(arguments.length == 1) {
    alert(arguments[0] + 5);
  } else if(arguments.length == 2) {
    alert(arguments[0] + arguments[1]);
  }
}

doAdd(10);	//output "15"
doAdd(40, 20);	//output "60"

When there is only one argument, the doAdd() function increments the argument by 5. If there are two arguments, the two arguments are added and their sum is returned. So, doAdd(10) outputs “15”, while doAdd(40, 20) outputs “60”.
It’s not as good as overloading, but it’s good enough to get around this limitation of ECMAScript.
Function overview Function object

Read More: