JS: Function's “arguments” Object

By Xah Lee. Date: . Last updated: .

There's a predefined variable named arguments inside the function body. It is a array-like object. Each slot is the value of argument.

Note, Arrow Function does not have the arguments object.

[see JS: Arrow Function]

function ff() {
    return arguments; // return the arguments object
}

console.log(
    ff(3,4,5)
);
// { '0': 3, '1': 4, '2': 5 }

When you define a function (except arrow function), you do not necessarily need to declare any parameters. The arguments can always be accessed via the object arguments in the function body.

「arguments」 is Array-Like Object

// “arguments” is a array-like object

function ff() {
    return Array.isArray(arguments);
}

console.log ( ff() ); // false

[see JS: Array-Like Object]

ES2015 Features Obsolete Arguments Object

Tip: you should avoid using the arguments object as much as possible. It makes code hard to understand, and has optimization problems.

ES2015 has features that obsolete the need for the argument object. See:

Reference

ECMAScript® 2016 Language Specification#sec-arguments-exotic-objects

JS Function

  1. Define Function
  2. Arrow Function ⭐
  3. Function Params
  4. “arguments” Object
  5. Rest Params ⭐
  6. Arg Default Value ⭐
  7. Arg Destructure ⭐
  8. f Declaration vs Expression
  9. Closure
  10. f call apply bind
  11. Functional Programing
Liket it? Put $5 at patreon.

Or, Buy JavaScript in Depth

If you have a question, put $5 at patreon and message me.

Web Dev Tutorials

  1. HTML
  2. Visual CSS
  3. JS in Depth
  4. JS Reference
  5. DOM
  6. SVG
  7. Web Dev Blog