I'm confused with Node.js function arguments object.
Suppose i have following code:
function x() {
return arguments;
}
console.log(x(1, 2, 3));
In chrome developer tools it returns as an Array:
[1, 2, 3]
But i got different result in node.js:
{ '0': 1, '1': 2, '2': 3 }
How come?
arguments is a magic variable that isn't actually an Array. It behaves like an Array, but it doesn't have all the functions that an Array has.
Other objects like this are NodeList for example.
You see different representation of an object which isn't array in Chrome neither in Node and in javascript in general.
If you want an array out of it, you do that:
var args = Array.prototype.slice.call(arguments, 0);
console.log is not part of javascript, and not part of v8. Which is why both chrome and node.js have there own implementations of console.log. They have simular apis, but not the same. The documentation for node's console.log is here: http://nodejs.org/api/stdio.html