Declares a new function.
Use the function statement to declare a function for later use. The code that is contained in statements is not executed until the function is called from elsewhere in the script.
The return statement is used to return a value from the function. You do not have to use a return statement; the program will return when it reaches the end of the function. If no return statement is executed in the function, or if the return statement has no expression, the function returns the value undefined.
When you call a function, be sure to always include the parentheses and any required arguments. Calling a function without parentheses causes the text of the function to be returned instead of the results of the function.
The following example illustrates the use of the function statement.
A function can be assigned to a variable. This is illustrated in the following example.
Supported in the following document modes: Quirks, Internet Explorer 6 standards, Internet Explorer 7 standards, Internet Explorer 8 standards, Internet Explorer 9 standards. See Version Information.