Core JavaScript

Functions with Variable Arguments

This JavaScript example demonstrates how to write and call a function with variable arguments.

FunctionsVariableArguments.html

<!DOCTYPE html>
<html>
<head>
    <title>XoaX.net's Javascript</title>
</head>
<body>
    <script type="text/javascript" src="FunctionsVariableArguments.js"></script>
</body>
</html>

FunctionsVariableArguments.js

function Print() {
	document.writeln("Inside Print()<br />");
	document.writeln("--------------<br />");
	for (var i = 0; i < arguments.length; i++) {
		document.writeln(arguments[i] + "<br />");
	}
	document.writeln("<br />");
}

// Call the function with string arguments
Print("Matthew", "Mark", "Luke", "John");

// Call the function with three arguments of various types.
Print(3.5, 83, "XoaX.net");
 

Output

 
 

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