Getting all arguments passed into a function

Within any function, you can use the arguments variable to get an array-like list of all of the arguments passed into the function.

The arguments parameter It is a local variable accessible within inside functions and contains an entry for each argument passed to that function. The arguments is an Array-like object which can be used to access arguments passed to the function even if a matching parameter isn’t explicitly defined.

function add() {

// Set a starting total
var total = 0;

// Add each number to the total
for (var i = 0; i < arguments.length; i++) {
total += arguments[i];
}

// Return to the total
return total;
};

--

--

Mohammed Nokri

Frontend Developer sharing weekly JS, HTML, CSS 🔥