User Guide

Table Of Contents
64 Chapter 3: Using ColdFusion Variables
Using quotation marks
To ensure that ColdFusion properly interprets string data, surround strings in single- or double-
quotation marks. For example, ColdFusion evaluates “10/2/2001” as a string that can be
converted into a date-time object. However, it evaluates 10/2/2001 as a mathematical expression,
5/2001, which evaluates to 0.00249875062469.
Examples of type conversion in expression evaluation
The following examples demonstrate ColdFusion expression evaluation.
Example 1
2 * True + "YES" - ('y' & "es")
Result value as string: "2"
Explanation: (2*True) is equal to 2; ("YES"- "yes") is equal to 0; 2 + 0 equals 2.
Example 2
"Five is " & 5
Result value as string: "Five is 5"
Explanation: 5 is converted to the string "5".
Example 3
DateFormat("October 30, 2001" + 1)
Result value as string: "31-Oct-01"
Explanation: The addition operator forces the string "October 30, 2001" to be converted to a
date-time object, and then to a number. The number is incremented by one. The DateFormat
function requires its argument to be a date-time object; thus, the result of the addition is
converted to a date-time object. One is added to the date-time object, moving it ahead by one day
to October 31, 2001.
About scopes
Variables differ in how they are set (by your code or by ColdFusion), the places in your code
where they are meaningful, and how long their values persist. These considerations are generally
referred to as a variables scope. Commonly used scopes include the Variables scope, the default
scope for variables that you create, and the Request scope, which is available for the duration of an
HTTP request.
Note: User-defined functions also belong to scopes. For more information, see Chapter 9,
“Specifying the scope of a function,” on page 194.