Open In App

How to use the Arguments Object in a Function in JavaScript ?

Last Updated : 02 Feb, 2024
Improve
Improve
Like Article
Like
Save
Share
Report

The arguments object is a special object available in JavaScript functions that holds all the parameters passed to the function. It allows you to access the arguments passed to a function even if the function was not explicitly defined with named parameters.

Example: Here, the exampleFunction takes no named parameters, but you can still access the arguments using the arguments object. The arguments object is similar to an array in that it has a length property and you can access its elements using numeric indices.

Javascript




function exampleFunction() {
  // Accessing arguments using the arguments object
  for (let i = 0; i < arguments.length; i++) {
    console.log(arguments[i]);
  }
}
 
// Calling the function with different arguments
exampleFunction(1, 'hello', true, [1, 2, 3]);


Output

1
hello
true
[ 1, 2, 3 ]

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads