Passing Values to Functions

The values you pass to functions are called arguments. When you pass data in arguments to a function, the code in the function has access to those values. When you create a function, you specify which arguments are to be passed to the function in an argument list.

Here's an example. In this case, I'll create a function named adder that will add two values and return their sum. Here's how I start creating adder:

function adder() 
{
    .
    .
    .
}

This time, we're going to pass arguments to the function. So, we list the arguments that we'll pass by giving them names in the argument list, which is enclosed in the parentheses following the function name. Here, I'll call the two arguments passed to addervalue1 and value2:

 function ...

Get Real World XML now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.