Defining a Function

A function is defined using the function statement. The function statement requires:

function functionName (argument1, argument2) {
  command block
}

The naming of functions follows basically the same rules as variables:

The list of arguments (parameters) passed to the function appears in parentheses and is separated by commas. The arguments are used to allow functions to import one or more values from outside the function. Even if the functions does not require arguments or parameters, you must supply the parentheses.


Functions | What is a Function? | Defining a Function | Calling a Function | Passing Data | Variable Scope | Global Access | Setting Default Values for Arguments | Passing Arguments by Reference | Returning Values from Functions | Returning References from Functions | Static Variables | Creating Variable Functions | Creating Conditional Functions | Creating Functions within Functions | Include Files | Require Statement | Testing a Function | Type-Testing Functions | Handling Errors Returned by Functions
© 2008: Hann So
email: hso@voyager.deanza.edu