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

Function Topic

  1. Define Function
  2. Functional Programing
  3. Arrow Function
  4. Function Parameters
  5. f Declaration vs Expression
  6. Closure
  7. Function Call, Apply, Bind
  8. Function Argument Default Value
  9. Function Rest Parameters
  10. Function Argument Destructure
  11. Function Object
  12. Function.prototype
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 Basics
  4. JS in Depth
  5. JS Reference
  6. DOM
  7. SVG
  8. JS Misc
  9. Web Dev Blog