HTML and CSS Reference
In-Depth Information
Figure 7.2 After the user clicks the OK button in the alert box, this image loads.
Passing Arguments. If a user wants to send values to a function, the values are
enclosed in the parentheses right after the function name and sent as a comma-separated
list of arguments when the function is called. The arguments are received by the func-
tion in a list of corresponding values called parameters (see Figure 7.3). The names of
the arguments are not necessarily the same names in the parameter list, but they corre-
spond to the same values. These values can be assigned to local variables within the
function. Local variables disappear when the function exits. JavaScript doesn't keep
track of the number of arguments sent to the function to make sure they match up with
the number of parameters specified in the function definition at the other end. If you
send three arguments, and there are only two parameters defined within the function,
the third argument is ignored. If you send three arguments, and there are four parame-
ters waiting within the function, then the fourth parameter is undefined . It's similar to
sending messages to an answering machine. If you send a message and the message
machine is full, your message is ignored, and if you send a message and there's room for
more messages, the message you sent is stored, and the unused space is still there, but not
defined.
function_name(argument1, argument2, ...); // function call (caller)
function_name(parameter1, parameter2...){ // function definition (receiver)
var result= parameter1 + parameter2;
...
}
// curly braces required
 
 
Search WWH ::




Custom Search