JS: arguments (object)
What is the argument object
- The
argumentsis a builtin variable, available in function body of functions defined via the keywordfunction. It is not available in Arrow Function. - The
argumentsobject is a Array-Like Object. Each index is the value of arguments of a function call.
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
JavaScript. Function
- JS: Define Function
- JS: Arrow Function
- JS: Function Parameters
- JS: arguments (object)
- JS: Function Rest Parameters
- JS: Function Parameter Default Value
- JS: Function Argument Destructure (Pattern Matching)
- JS: Function. Declaration vs Expression
- JS: Closure
- JS: Function Call, Apply, Bind
- JS: Functional Programing
- JS: Function Pipe 📜
- JS: Function (class)
- JS: Function Constructor
- JS: Function.prototype