Function Arguments and Parameters

Option Parameters

when designing functions with optional arguments, you should be sure to put the optional ones at the end of the argument list so that they can be omitted.

Also note the use of the comment / optional / in the function definition to emphasize the fact that the parameter is optional.

    function getPropertyNames(o, /* optional */ a) {
        a = a || [];
        for(var property in o) a.push(property);
        return a;
    }
    // This function can be invoked with 1 or 2 arguments:
    var a = getPropertyNames(o); 
    getPropertyNames(p,a);

Variable-Length Argument Lists: The Arguments Object

When a function is invoked with more argument values than there are parameter names, there is no way to directly refer to the unnamed values. The Arguments object provides a solution to this problem。

Using Object Properties As Arguments

Argument Types