Specifying quotation marks around values

When you assign literal values to variables, you must surround the literal value with single- or double-quotation marks. ColdFusion interprets the content between the quotation marks as a literal value and assigns that value to the variable; for example:

<cfset my_first_name = "Kaleigh">
<cfset my_last_name = "Smith">
<cfset my_age = 5>

ColdFusion instantiates the variable my_first_name to the string literal Kaleigh. Further, Smith is assigned to the variable my_last_name and 5 is assigned to age.

When referencing a variable by its name, you do not surround the name with quotation marks. In the following example, when you concatenate literal text and variables using the & operator, you don’t surround the variable references with quotation marks:

<cfset the_string = "My name is " & variables.my_first_name & 
" and my age is " & variables.my_age>

My name is is literal text, and you, therefore, surround it with quotation marks. The variable references variables.my_first_name and variables.my_age are not surrounded by quotation marks. ColdFusion uses the values of the referenced variables (Kaleigh and 5, respectively) when assigning the value to the variable the_string.

To display quotation marks on a page as literal characters, you must use two consecutive quotation marks; for example:

<cfset mystring = "We all shouted ""Happy Birthday"" when he entered the room.">
<cfoutput>
	#mystring#
</cfoutput>

The result is the following output:

We all shouted "Happy Birthday" when he entered the room.