Functions are defined with the
function keyword, which can be used in a
function definition expression (Function Definition Expressions) or
in a function declaration statement (function). In either form, function definitions
begin with the keyword
followed by these components:
An identifier that names the function. The name is a required part of function declaration statements: it is used as the name of a variable, and the newly defined function object is assigned to the variable. For function definition expressions, the name is optional: if present, the name refers to the function object only within the body of the function itself.
A pair of parentheses around a comma-separated list of zero or more identifiers. These identifiers are the parameter names for the function, and they behave like local variables within the body of the function.
Example 8-1 shows some function definitions using both statement and expression forms. Notice that a function defined as an expression is only useful if it is part of a larger expression, such as an assignment or invocation, that does something with the newly defined function.
// Print the name and value of each property of o. Return undefined.