JavaScript parameter number variable function example

  • 2020-03-30 04:05:54
  • OfStack

Aside: I have been exposed to JavaScript for a long time, but I did not pay attention to it. I saw many cool and cool web pages with JavaScript in them. The application of Google in JavaScript had the greatest impact on me. I was determined to learn it from scratch, so I had the JavaScript & Ajax column. I'm going to write this column down as a study note, so each essay note will probably be short, one or two sentences notes.

JavaScript allows a function to pass a variable number of arguments, because there is a built-in object called arguments, which is an array of all arguments passed by the function. For example, you can see.

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JavaScript A function with a variable number of arguments </title>
<mce:script language="javascript" type="text/javascript"><!--
function testparams()
var params = "";
for (var i=0; i<arguments.length; i++) {
params = params + " " + arguments[i];

testparams("abc", 123);
testparams(123, "456", 789);
// --></mce:script>

Related articles: