Hello Everyone,
I’m learning JavaScript nowadays and have a query. Consider a function with following declaration.
function args1()
{
var a = [1,2,3];
return a;
}
When I try to call above function as below, return type is array
alert (typeof args1(1,2,3)); //array
alert (args1(1,2,3)); //1,2,3
But this is not true for local array variable “arguments” which JavaScript creates
function args2()
{
return arguments;
}
alert (typeof args2(1,2,3)); //object
alert (args2(1,2,3)); //[object][object]
In both situations, function is expected to return array values. It is an array in first case but object in second case. Could anyone please explain on this? Why it is so?