Skip to content

JavaScript Arguments Object | Example code

  • by

JavaScript Arguments Object contains the values of the arguments passed to that function. This is an Array-like object accessible inside functions that have the values of the arguments passed to that function.

function func1(a, b, c) {
      console.log(arguments[0]);
      
      console.log(arguments[1]);

      console.log(arguments[2]);
    }

func1(1, 2, 3);

JavaScript Arguments Object

Simple example code.

<!DOCTYPE html>
<html>
<body>
  <script>

    function test(a, b, c) {
      console.log("Printing arguments: ", arguments[0], arguments[1], arguments[2]);
    }
    test(1,2,3); 
  </script>

</body>
</html> 

Output:

JavaScript Arguments Object

Length property that contains the number of arguments passed to the function.

function test(a, b, c) {
 console.log(arguments.length);
}
test(1); // 1
test(1, 2); // 2

Use many parameters in the function declaration.

function test() {
 console.log(arguments.length);
}

test();  //0
test(1);  //1
test(1,2,3,5);  //4

Do comment if you have any doubts or suggestions on this Js object topic.

Note: The All JS Examples codes are tested on the Firefox browser and the Chrome browser.

OS: Windows 10

Code: HTML 5 Version

Leave a Reply

Discover more from Tutorial

Subscribe now to keep reading and get access to the full archive.

Continue reading