InterviewHubPRO
Section Overview
Q133

Question 133 of 521

Part 3: DOM, Event Flow, Timers & Browser APIs (104 - 173)

26%
JavaScript Internals (521 Qs)•Part 3: DOM, Event Flow, Timers & Browser APIs (104 - 173)

What is an arguments object

The arguments object is an Array-like object accessible inside functions that contains the values of the arguments passed to that function. For example, let's see how to use arguments object inside sum function,

javascript
  function sum() {
    var total = 0;
    for (var i = 0, len = arguments.length; i < len; ++i) {
      total += arguments[i];
    }
    return total;
  }

  sum(1, 2, 3); // returns 6

Note: You can't apply array methods on arguments object. But you can convert into a regular array as below.

javascript
  var argsArray = Array.prototype.slice.call(arguments);