The second is quite dangerous and will not always work. Try:
console.log(returnArgs2(3));
This will show an empty array of length 3. The Array constructor interprets one numeric argument as meaning that you need an array of this length.
edit — , , "" , "" arguments, , arguments , arguments . , :
function returnArgs() {
var rv = [];
for (var i = 0; i < arguments.length; ++i)
rv.push(arguments[i]);
return rv;
}
arguments.length , arguments, , . , " " , .
"" arguments , . :
function foo(a, b) {
arguments[1] = a;
return b;
}
alert(foo("hello", "world"));
arguments[1] , b . , arguments "" , , ( ), .
, V8, . Nashorn, JDK 8, , , arguments .