Use functionName.arguments to reference the arguments in JavaScript

Description

The following code shows how to use functionName.arguments to reference the arguments.

Example


<!--from w  ww. ja v  a  2s.c  o m-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">

function addNums () {
var theAnswer = 0;
for (var i = 0; i < addNums.arguments.length; i++) {
var theNum = Number(addNums.arguments[i]);
theAnswer += theNum;
}
return theAnswer;
}
document.write(addNums(1,2,3,4));
</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Use functionName.arguments to reference the arguments in JavaScript