Arguments

This can be omitted at a first reading. The main point here is that in JavaScript

  1. There is no checking for number and type of arguments.
  2. The arguments actually supplied are stored in a special variable, called arguments.
  3. The value of arguments is almost, but not exactly, an array.

Test code

TEST('return_arguments', function()
{
    var return_arguments = function(){
        return arguments;
    };

    var my_arguments = return_arguments(0, 1);

    assert( my_arguments.length === 2 );

    assert( my_arguments[0]  === 0 );
    assert( my_arguments[1]  === 1 );

    assert( '' + my_arguments === '[object Object]' );
    assert( '' + [0, 1] === '0,1' );

    var array_slice = [].slice;
    var my_arguments_fixed = array_slice.call( my_arguments );

    assert( '' + my_arguments_fixed === '0,1');

    var obj = {};
    assert( obj.toString.call( my_arguments_fixed ) === '[object Array]' );

});