CFScript is an extension of CFML on the ColdFusion platform. CFScript resembles JavaScript. Some ColdFusion developers prefer it since it has less visual and typographical overhead than ordinary CFML.
It is considered best practice to write ColdFusion Components and all business logic in CFScript and to use CFML only in .cfm files amongst HTML.
All CFScript code must be contained within a CFScript tag pair as follows, unless it's within a pure script-based ColdFusion Component.
A simple example of a function:
A simple example of a component in CFScript, containing two functions:
ColdFusion 11, Railo 4.1+ and Lucee 4.5+ both do their best to fully support cf tags in CFScript. While there may not be direct substitutions for all tags, it is often still possible to achieve the results of a tag in script, but via a different syntax. For example, this is how to get a query into a variable in CFSCRIPT without writing a UDF:
Since ColdFusion 8, CFScript has supported syntax abbreviations that are common in many other programming languages, such as "++", "<=" and "+=".
In division, the right operand cannot be zero.
These operators can be used for pre-incrementing or decrementing (as in x = ++ i), where the variable is changed before it is used in the expression. They can also be used for post-incrementing or decrementing (as in x = i++), where the value is changed after it is used in the expression. If the value of the variable i is initially 7, for example, the value of x in x = ++i is 8 after expression evaluation, but in x=i++, the value of x is 7. In both cases, the value of i becomes 8.
These operators cannot be used with expressions that involve functions, as in f().a++. Also, you can use an expression such as -++x, but ---x and +++x cause errors, because their meanings are ambiguous. You can use parentheses to group the operators, as in -(--x) or +(++x), however.
An expression can have only one compound assignment operator.
CFScript has two forms of comments: single line and multiline.
Although CFScript and JavaScript are similar, they have several key differences. The following list identifies CFScript features that differ from JavaScript: