User Guide

Table Of Contents
Creating user-defined functions 173
The following is a CFScript definition for a function that returns a power of 2:
<cfscript>
function twoPower(exponent) {
return 2^exponent;
}
</cfscript>
For more information on how to use CFScript to define a function, see “Defining functions in
CFScript” on page 173.
Defining functions in CFScript
You define functions using CFScript in a manner similar to defining JavaScript functions. You
can define multiple functions in a single CFScript block.
Note: For more information on using CFScript, see Chapter 6, “Extending ColdFusion Pages with
CFML Scripting,” on page 123.
CFScript function definition syntax
A CFScript function definition has the following syntax:
function functionName( [argName1[, argName2...]] )
{
CFScript Statements
}
The following table describes the function variables:
The body of the function definition must be in curly braces, even if it is a empty.
Function variable Description
functionName The name of the function. You cannot use the name of a standard
ColdFusion function or any name that starts with “cf”. You cannot use the
same name for two different function definitions. Function names cannot
include periods.
argName1... Names of the arguments required by the function. The number of arguments
passed into the function must equal or exceed the number of arguments in
the parentheses at the start of the function definition. If the calling page omits
any of the required arguments, ColdFusion generates a mismatched
argument count error.