var a = [1,2,3];
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
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?
The arguments object is an array-like object, but it is not an actual array. It cannot be just an array because changing a value in the arguments object also changes the corresponsing function parameter as well. You can convert the arguments object to an array though, if you require the information in that data format.