by Tom Millard

Arguments array in JavaScript Functions


Arguments is something I stumbled upon whilst looking through my twitter feed the other day, so I chose to do a little bit of research.

Argument is a local variable available within a function. Arguments contains an array of each argument passed into the function, starting at an index of 0.

var x = function(){return arguments}

will return..


So thats about it, personally I find this approach a bit vague and would prefer declared arguments, however if you are interested in this approach maybe an object would be better.

var y = function(options){ return options.time };

which will return

>y({time : new Date()})
>Mon Aug 04 2014 21:23:21 GMT+0100 (BST)

I find this gives a little more structure to your function arguments.

Let me know your thoughts: @millard_.

Some lovely examples can be found on - MDN