For the complete experience, please enable JavaScript in your browser. Thank you!

  • Creative Cloud
  • Photoshop
  • Illustrator
  • InDesign
  • Premiere Pro
  • After Effects
  • Lightroom
  • See all
  • See plans for: businesses photographers students
  • Document Cloud
  • Acrobat DC
  • eSign
  • Stock
  • Elements
  • Marketing Cloud
  • Analytics
  • Audience Manager
  • Campaign
  • Experience Manager
  • Media Optimizer
  • Target
  • See all
  • Acrobat Reader DC
  • Adobe Flash Player
  • Adobe AIR
  • Adobe Shockwave Player
  • All products
  • Creative Cloud
  • Individuals
  • Photographers
  • Students and Teachers
  • Business
  • Schools and Universities
  • Marketing Cloud
  • Document Cloud
  • Stock
  • Elements
  • All products
  • Get Support
    Find answers quickly. Contact us if you need to.
    Start now >
  • Learn the apps
    Get started or learn new ways to work.
    Learn now >
  • Ask the community
    Post questions and get answers from experts.
    Start now >
    • About Us
    • Careers At Adobe
    • Investor Relations
    • Privacy  |  Security
    • Corporate Responsibility
    • Customer Showcase
    • Events
    • Contact Us
News
    • 3/22/2016
      Adobe Summit 2016: Are You An Experience Business?
    • 3/22/2016
      Adobe Announces Cross-Device Co-op to Enable People-Based Marketing
    • 3/22/2016
      Adobe and comScore Advance Digital TV and Ad Measurement
    • 3/22/2016
      Adobe Marketing Cloud Redefines TV Experience
Developing Applications Help / 

The CFScript language

Adobe Community Help


Applies to

  • ColdFusion

Contact support

 
By clicking Submit, you accept the Adobe Terms of Use.
 

The CFScript language syntax is similar to other scripting languages, and has the same types of elements.

Identifying CFScript

You enclose CFScript regions inside <cfscript> and </cfscript> tags. No other CFML tags are allowed inside a cfscript region. The following lines show a minimal script:

<cfscript> 
a = 2; 
</cfscript>

Variables

CFScript variables can be of any ColdFusion type, such as numbers, strings, arrays, queries, and objects. The CFScript code can read and write any variables that are available in the page that contains the script. These variables include all shared scopes, such as session, application, and server variables.

Expressions and operators

CFScript supports all CFML expressions. CFML expressions include operators (such as +, -, EQ, and so on), as well as all CFML functions. 
You can use several comparison operators in CFScript only, not in CFML tags. (You can also use the corresponding CFML operators in CFScript.) The following table lists the CFScript-only operators and the equivalent operator that you can use in CFML tags or CFScript:

CFScript operator

CFML operator

CFScript operator

CFML operator

==

EQ

!=

NEQ

<

LT

<=

LTE

>

GT

>=

GTE

For information about CFML expressions, operators, and functions, see Using Expressions and Number Signs.

Statements

CFScript supports the following statements:

assignment

for-in

try-catch

function call

while

function (function definition)

if-else

do-while

var (in custom functions only)

switch-case-default

break

return (in custom functions only)

for

continue

 

The following rules apply to statements:

  • You must put a semicolon at the end of a statement.
  • Line breaks are ignored. A single statement can cross multiple lines.
  • White space is ignored. For example, it does not matter whether you precede a semicolon with a space character.
  • Use curly brackets to group multiple statements into one logical statement unit.
  • Unless otherwise indicated, you can use any ColdFusion expression in the body of a statement.

Note

For information on the function, var, and return statements, see Defining components and functions in CFScript.

Statement blocks

Curly bracket characters ({ and }) group multiple CFScript
statements so that they are treated as a single unit or statement.
This syntax enables you to create code blocks in conditional statements,
such as the following:

if(score GT 0) 
{ 
	result = "positive"; 
	Positives = Positives + 1; 
}

In this example, both assignment statements are executed if the score is greater than 0. If they were not in the code block, only the first line would execute.
You do not have to place curly bracket characters on their own lines in the code. For example, you could place the open curly bracket in the preceding example on the same line as the if statement, and some programmers use this style. However, putting at least the ending brace on its own line makes it easier to read the code and separate code blocks.

Comments

CFScript has two forms of comments: single line and multiline. 
A single-line comment begins with two forward slashes (//) and ends at the line end; for example:

//This is a single-line comment. 
//This is a second single-line comment.

A multiline comment starts with a /* marker and continues until it reaches a */ marker; for example:

/*This is a multiline comment. 
	 You do not need to start each line with a comment indicator. 
	 This line is the last line in the comment. */

The following rules apply to comments:

  • Comments do not have to start at the beginning of a line. They can follow active code on a line. For example, the following line is valid:

MyVariable = 12; // Set MyVariable to the default value.
  • The end of a multiline comment can be followed on the same line by active code. For example, the following line is valid, although it is poor coding practice:
End of my long comment */ foo = "bar";
  • You can use multiline format for a comment on a single line, for example:
/*This is a single-line comment using multiline format. */
  • You cannot nest /* and */ markers inside other comment lines.
  • CFML comments (<!--- and --->) do not work in CFScript.

Differences from JavaScript

Although CFScript and JavaScript are similar, they have several key differences. The following list identifies CFScript features that differ from JavaScript:

  • CFScript uses ColdFusion expressions, which are not a superset or a subset of JavaScript expressions. In particular, ColdFusion expressions do not support bitwise operators, and the ColdFusion MOD or % operator operates differently from the corresponding JavaScript % operator: In ColdFusion, the operator does integer arithmetic and ignores fractional parts. ColdFusion expressions also support the EQV, IMP, CONTAINS, and DOES NOT CONTAIN operators that are not supported in JavaScript.
  • Variable declarations (var keyword) are only used in user-defined functions and threads.
  • CFScript is not case sensitive.
  • All statements end with a semicolon, and line breaks in the code are ignored.
  • Assignments are statements, not expressions, and therefore cannot be used in situations that require evaluating the assignment operation.
  • JavaScript objects, such as Window and Document, are not available.
  • Only the ColdFusion server processes CFScript. There is no client-side CFScript.

CFScript limitation

You cannot include ColdFusion tags in CFScript. However, you can include cfscript blocks inside other ColdFusion tags, such as cfoutput.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License  Twitter™ and Facebook posts are not covered under the terms of Creative Commons.

Legal Notices   |   Online Privacy Policy

Choose your region United States (Change)   Products   Downloads   Learn & Support   Company
Choose your region Close

Americas

Europe, Middle East and Africa

Asia Pacific

  • Brasil
  • Canada - English
  • Canada - Français
  • Latinoamérica
  • México
  • United States
  • Africa - English
  • Österreich - Deutsch
  • Belgium - English
  • Belgique - Français
  • België - Nederlands
  • България
  • Hrvatska
  • Cyprus - English
  • Česká republika
  • Danmark
  • Eesti
  • Suomi
  • France
  • Deutschland
  • Greece - English
  • Magyarország
  • Ireland
  • Israel - English
  • ישראל - עברית
  • Italia
  • Latvija
  • Lietuva
  • Luxembourg - Deutsch
  • Luxembourg - English
  • Luxembourg - Français
  • Malta - English
  • الشرق الأوسط وشمال أفريقيا - اللغة العربية
  • Middle East and North Africa - English
  • Moyen-Orient et Afrique du Nord - Français
  • Nederland
  • Norge
  • Polska
  • Portugal
  • România
  • Россия
  • Srbija
  • Slovensko
  • Slovenija
  • España
  • Sverige
  • Schweiz - Deutsch
  • Suisse - Français
  • Svizzera - Italiano
  • Türkiye
  • Україна
  • United Kingdom
  • Australia
  • 中国
  • 中國香港特別行政區
  • Hong Kong S.A.R. of China
  • India - English
  • 日本
  • 한국
  • New Zealand
  • Southeast Asia (Includes Indonesia, Malaysia, Philippines, Singapore, Thailand, and Vietnam) - English
  • 台灣

Commonwealth of Independent States

  • Includes Armenia, Azerbaijan, Belarus, Georgia, Moldova, Kazakhstan, Kyrgyzstan, Tajikistan, Turkmenistan, Ukraine, Uzbekistan

Copyright © 2016 Adobe Systems Incorporated. All rights reserved.

Terms of Use | Privacy | Cookies

AdChoices