Core JavaScript

Passing Too Many Or Too Few Arguments

This JavaScript example illustrates what happens when too many or too few arguments are passed into a function. When too many arguments are passed, the additional arguments may be accessed via the arguments object. When too few arguments are passed, the additional paramters are undefined.

TooManyOrTooFewArguments.html

<!DOCTYPE html>
<html>
  <head>
    <title>XoaX.net's Javascript</title>
    <script type="text/javascript" src="TooManyOrTooFewArguments.js"></script>
  </head>
  <body onload="Initialize()">
  </body>
</html>

TooManyOrTooFewArguments.js

function F(x, y) {
	document.writeln(`x = ${x} : y = ${y}` +"<br />");
	for (qArg in arguments) {
  	document.writeln(qArg + " : " + arguments[qArg] + "<br />");
	}
	document.writeln("<br />");
}

function Initialize() {
	F();
	F("XoaX.net");
	F("XoaX", ".net");
	F("XoaX", ".net", "says", "Hello!");
}
 

Output

 
 

© 2007–2025 XoaX.net LLC. All rights reserved.