Get function parameter length in JavaScript

Description

The following code shows how to get function parameter length.

Example


<!--  w  w  w . j a v a2 s  .  c om-->
<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
function addTwoNumbers(a, b) {
document.writeln(arguments.length);
}

var result = addTwoNumbers(90);
</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Get function parameter length in JavaScript