JS: arguments (object)

By Xah Lee. Date: . Last updated: .

What is the argument object

function ff() {
 return arguments;
}

// show the arguments object
console.log(ff(800, 638));
// [Arguments] { "0": 800, "1": 638 }

// show its length
console.log(ff(800, 638).length);
// 2

// show all its keys
console.log(Reflect.ownKeys(ff(800, 638)));
// [ "0", "1", "length", "callee", Symbol(Symbol.iterator) ]

// not a true array
console.log(Array.isArray(ff()) === false);
// true

Purpose of the argument object

In 1995, the purpose of the argument object was to allow function to take arbitrary number of arguments, such as plus function.

It is no longer needed today because Rest Parameters feature was added to JavaScript.

🟢 TIP: never use the argument object