Programming instructions

20 Chapter 2 CFML Basics
In the next example, ColdFusion uses the values of the my_first_name and
my_last_name variables to set the value for the my_full_name variable in the last line of
code. The ampersand (
&) string operator joins the variables, and the space surrounded by
double quotation marks (
" ") adds a space between the variables.
<cfset my_first_name = "Kaleigh">
<cfset my_last_name = "Smith">
<cfset my_full_name = variables.my_first_name & " " & variables.my_last_name>
Tip: String values assigned to a variable must be enclosed in single (’) or double (")
quotation marks. Numeric or Boolean values assigned to a variable do not require single or
double quotation marks.
So far all the variable examples shown have been about local variables. Local variables are
variables that you can use only on the current ColdFusion page. As shown in the previous
example, a Variables prefix was used to reference an existing variable on the page. Using a
prefix when referencing a variable is important because ColdFusion supports many types
of variables. The syntax for referencing a local variable is as follows:
variables.variablename
Because ColdFusion lets you use the same name with variables of more than one type,
ColdFusion relies on scope referencing. In scope referencing, you preface the variables
name with the scope when you refer to that variable.
Other variables and their scope
ColdFusion supports many types of variables. Each type has it own scope, or where it can
be referenced, and its own way of referencing that variable type. The following table
identifies some of the more common types of variables and their prefixes:
You will use these other types of variables in Part II of this book. For additional
information about variables, see CFML Reference.
Displaying variable output
Output is what remains after the ColdFusion server processes the CFML tags on a page.
Usually the output has two parts:
Information that the user sees (for example, a confirmation message)
Information that is stored by the server as a result of processing (for example, user
input collected from a form)
Scope Prefix Description
variables
(local variable)
Variables Variables created using cfset or cfparam. Most often you
define the variable on the current page or on a page that you
include using cfinclude.
Form Form Data entered in tags in an HTML form or ColdFusion form
and processed on the action page.
URL URL Variables passed to a page as URL string parameters.
Query QueryName Variables that are named based on the column names that
you select in the database table. The values are created when
you execute the query that selects data from the database.