Make your own free website on

Complex scripts require functions. They are usually controlled by an event, such as clicking a form button. To write a function, one of these basic formats must be followed:

function the_function_name() { }
function the_function_name(variable_1, variable_2) { }

The command lines of the function are between the pair of curly braces { }.

Global and Internal Variables
If you declare a variable inside of a function:
function some_function() {var some_variable = 117}
It will cease to exist when the run of the function completes. Under rare circumstances this can conserve memory. In javascript variable declaration is optional.

Returning Values
The statement:
return 170;
will cease the run of the function and send the value specified (170) to the location of the function call. If the function was called in the command line:
variable_x = the_function_that_returns_170()
variable_x will become equal to 170.

Function Construction
Under some conditions you can create a function with the new statement. Under some conditions this is handy, but it is somewhat limited.