Everything You Must Know About ColdFusion Variables - Variable by assigning statements in CFSCRIPT
(Page 4 of 7 )
It was mentioned earlier that CFSCRIPT can be used to assign variables. Here is an example of such an assignment. In CSPT.cfm, three numbers are assigned to the variables m, n, and p. There are rules to be followed in using CFSCRIPT, but these will be discussed later. Notice the ColdFusion comment. It has an extra dash, three compared to two in an HTML comment.
Syntax<CFSCRIPT>
The CFSCRIPT code goes here, review the example
</CFSCRIPT>
<!--- Usage of CFSCRIPT--->
<!---File Name:CSPT.cfm--->
<cfscript>
m=5;
n=1.5;
p=2;
WriteOutput("The value of (5 + 1.5) divided by 2 is: ");
WriteOutput((n+m)/p);
</cfscript>
This code will be processed by the CFMX as shown in this picture. CFSCRIPT is only processed by the server. It may not contain CFML tags, and statements are terminated by a semicolon (similar to JavaScript). The same assignment with CFML would have taken three <cfset /> tags plus the <cfoutput />. The display in CFSCRIPT is by using the WriteOutput() syntax. You may also notice the absence of CFML tags inside <cfscript />

Characteristics of Variables
Variables in ColdFusion are characterized by the following:
- Scope of the variable -- This covers where and how long the variable is accessible.
- Data type of the variable -- This covers the kind of information that the variable represents, number, strings, Boolean, and so on.
Next: Scope of a variable >>
More ColdFusion Articles
More By Jayaram Krishnaswamy