/*ACCEPTING ANY NUMBER OF ARGUMENTS*/
/* you can use arguments.length as the basis of a quick test to see that a function was called with the proper
number of arguments: */
/*function functionName(someVar, anotherVar, yetAnotherVar) {
if (arguments.length == 3) { alert('Good to go!');
} else { alert('Missing something!');
}
console.log(length);
}
functionName('Hello, ', 'World', '!');*/
/*You can also use a for loop within the function to loop through every received argument:*/
/*for (var i = 0, count = arguments.length; i < count; i++) {
// Do something with arguments[i].
}*/
/*The arguments variable is used all over the place in JavaScript’s built-in methods, such as the concat()
method, which can take any number of values to be concatenated together:*/
//myArray.concat(1);
//myArray.concat(2, 3, 4);
/* There is one more way to pass a variable number of values to a function, and that’s to only pass one argument, but of type object:*/
/* but you can also write functions to purposefully take
a variable number of arguments, as discussed */
function showText(argObject) {
// Use argObject.
console.log(argObject);
}
showText({text: 'Hello, World!', bold: true, size: 12});
Please Whitelist JSFiddle in your content blocker.
Help keep JSFiddle free for always by one of two ways:
Whitelist JSFiddle in your content blocker (two clicks)
Go PRO and get access to additional PRO features →
Join the 4+ million users, and keep the JSFiddle dream alive.
Ad-free
All ads in the editor and listing pages are turned completely off.
Use pre-released features
You get to try and use features (like the Palette Color Generator) months before everyone else.
Fiddle collections
Sort and categorize your Fiddles into multiple collections.
Private collections and fiddles
You can make as many Private Fiddles, and Private Collections as you wish!
Console
Debug your Fiddle with a minimal built-in JavaScript console.