Skip to main content
InterviewHubPRO
Section Overview
Q133

Question 133 of 536

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

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

What is an arguments object

junior LevelCode ExampleHTTP & REST APIs

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);