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

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 ]



Reffered: https://www.geeksforgeeks.org


JavaScript

Related
JavaScript innerHTML JavaScript innerHTML
How to Replace an Object in an Array with Another Object Based on Property ? How to Replace an Object in an Array with Another Object Based on Property ?
Driver.js a JavaScript Framework Driver.js a JavaScript Framework
What are JavaScript Events ? What are JavaScript Events ?
JavaScript Exercises, Practice Questions and Solutions JavaScript Exercises, Practice Questions and Solutions

Type:
Geek
Category:
Coding
Sub Category:
Tutorial
Uploaded by:
Admin
Views:
12