What Are Functions?

In their simplest form, functions are a group of statements that do something and that are placed under one name. A function takes the following form:

function functionname()
{
statements go here!;
}

A function consists of the word function followed by the name you give the function, such as yourMessage. Then, parentheses are placed after the function name—for example, yourMessage(). These are required, and an error is generated if they are omitted.

NOTE

For the moment, these parentheses will remain empty. Later in this chapter, you'll see what they are used for.

After the parentheses are the opening and closing curly braces, in between which are the statements.

Each function you use must be given a name, and no two functions ...

Get JavaScript™ 1.5 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.