So What is a Function???

In JavaScript, a function is a complete section of program code that performs a specific task or a group of related tasks.

JavaScript functions can work together using the tasks of one function to help another function, to make tests, get input, give output, perform processes (such as arithmetic), and return values.

Good grief!  Am I functional?

Why Use Functions???

Breaking JavaScript code into groups of functions can make your code easier to read and understand.

You can reuse functions.  You can write a function once and use it as many times as you want.

  Your programs actually become smaller with functions because you eliminate lines of code by reusing the function.

Sounds good to me!

Rolling Your Own Functions...

The basic structure of a JavaScript function is:

   
function MyName( )
    {

    }

 
The basic parts are:
   
function  <= A reserved word that must be used.
   
MyName <= Any legal variable identifier you want to make up.
   
( )           <= Required parenthesizes.
   
           <= Required opening brace.
   
}             <= Require closing brace.

  The JavaScript code for the function goes between the opening brace
} and the closing brace {.

Note that function
MyName( ) does not end with a semicolon!


Next Page for Examples...

Think we need some examples.

Copyright © 2000 Adamson House, Ltd.