January 2003
Beginner to intermediate
1200 pages
23h 42m
English
Functions are a crucial part of JavaScript programming. With a function, you can wrap some code into a programming construct, a function, and you then call that function to execute that code.
You create functions with the function statement. Here's how that statement looks in outline:
function functionname([argument1 [, argument2 [, ...argumentn]]])
{
code
}
In this case, I'm passing the values argument1, argument2, and so on to this function. The code in the function has access to these values. A function can also return a value; to do that, you use the return statement.
Here's an example. In this case, I'm creating a function named getTime, which will return the current time. Notice the syntax of the function ...