BASIC FUNCTIONS
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() { }
or
function the_function_name(variable_1, variable_2) { }
The command lines of the function are between the pair of curly braces { }.
ADVANCED FUNCTIONS
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.