User Guide

Table Of Contents
123
CHAPTER 6
Extending ColdFusion Pages with CFML Scripting
Macromedia ColdFusion MX offers a server-side scripting language, CFScript, that provides
ColdFusion functionality in script syntax. This JavaScript-like language gives developers the same
control flow as ColdFusion, but without tags. You can also use CFScript to write user-defined
functions that you can use anywhere that a ColdFusion expression is allowed.
This chapter describes the CFScript language’s functionality and syntax, and provides
information on using CFScript effectively in ColdFusion pages.
Contents
About CFScript . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
The CFScript language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
Using CFScript statements. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Handling exceptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
CFScript example . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 137
About CFScript
CFScript is a language within a language. It is a scripting language that is similar to JavaScript but
is simpler to use. Also, unlike JavaScript, CFScript only runs on the ColdFusion server; it does
not run on the client system. CFScript code can use all the ColdFusion functions and expressions,
and has access to all ColdFusion variables that are available in the scripts scope.
CFScript provides a compact and efficient way to write ColdFusion logic. Typical uses of
CFScript include the following:
Simplifying and speeding variable setting
Building compact JavaScript-like flow control structures
Creating user-defined functions
Because you use functions and expressions directly in CFScript, you do not have to surround
each assignment or function in a
cfset tag. Also, CFScript assignments are often faster than
cfset tags.
CFScript provides a set of decision and flow-control structures that are more familiar than
ColdFusion tags to most programmers.