Operators are symbols that tell ColdFusion to perform an operation on one or more values. You use operators every day while writing CFML — adding numbers, comparing values, combining text, checking conditions, and assigning values to variables.
For example, when calculating a total price, comparing a user's age, or checking whether someone is logged in, you're using operators.
By the end of this lesson, you'll understand the most commonly used ColdFusion operators and know when to use each one.
Learning Objectives
After completing this lesson, you'll be able to:
- Understand what operators are.
- Use arithmetic operators.
- Use assignment operators.
- Compare values, in both CFScript symbols and tag-syntax words.
- Work with logical operators.
- Concatenate strings.
- Use the ternary operator.
- Write operator expressions in both CFScript and Tag Syntax.
What Is an Operator?
An operator performs an action on one or more values (called operands).
- Operand — a value used in an operation, e.g., 10 and 20.
- Operator — the symbol that performs the operation on those operands, e.g., +.
Here, 10 and 20 are operands, and + is the operator.
Types of Operators
ColdFusion provides several categories of operators.
| Category | Purpose |
|---|---|
| Arithmetic | Mathematical calculations |
| Assignment | Assign values |
| Comparison | Compare values |
| Logical | Combine conditions |
| String | Join text |
| Ternary | Short if...else |
Arithmetic Operators
Arithmetic operators perform mathematical calculations.
| Operator | Description | Example |
|---|---|---|
| + | Addition | 10 + 5 |
| - | Subtraction | 10 - 5 |
| * | Multiplication | 10 * 5 |
| / | Division | 10 / 5 |
| % | Modulus (Remainder) | 10 % 3 |
Assignment Operator
The assignment operator (=) stores a value in a variable.
Comparison Operators
Comparison operators compare two values and always return either true or false.
| Operator | Meaning |
|---|---|
| == | Equal |
| != | Not Equal |
| > | Greater Than |
| < | Less Than |
| >= | Greater Than or Equal |
| <= | Less Than or Equal |
In tag syntax, you'll often see operator keywords such as EQ, NEQ, GT, LT, GTE, and LTE instead of symbols. Both styles work, but many developers prefer the word versions inside tag-based code.
CFML vs CFScript Operators
Beginners often get confused when they see EQ, GT, LTE in tag syntax but ==, >, <= in CFScript. Here's both side by side.
| Purpose | Tag Syntax (CFML) | CFScript |
|---|---|---|
| Equal | EQ, IS, EQUAL | == |
| Not Equal | NEQ, IS NOT, NOT EQUAL | != |
| Greater Than | GT, GREATER THAN | > |
| Less Than | LT, LESS THAN | < |
| Greater Than or Equal | GTE | >= |
| Less Than or Equal | LTE | <= |
| Contains | CONTAINS | use contains() or find() |
| Does Not Contain | DOES NOT CONTAIN | use !contains() or find() == 0 |
String Comparison
String Contains
Tag syntax has a dedicated CONTAINS operator. CFScript doesn't — use a string function like contains() or find() instead.
For maximum compatibility across ColdFusion versions, find("Cold", text) works the same way as text.contains("Cold").
Logical Operators
Logical operators combine multiple conditions and always return either true or false.
| Purpose | Tag Syntax (CFML) | CFScript |
|---|---|---|
| Logical AND | AND | && |
| Logical OR | OR | || |
| Logical NOT | NOT | ! |
| Logical XOR (Exclusive OR) | XOR | XOR |
| Logical EQV (Equivalent) | EQV | EQV |
| Logical IMP (Implication) | IMP | IMP |
AND
Returns true only if both conditions are true.
OR
Returns true if at least one condition is true.
NOT
Reverses a Boolean value.
Advanced Logical Operators (XOR, EQV, IMP)
AND, OR, and NOT are used every day in real ColdFusion development. XOR (exclusive OR — true only if exactly one side is true) shows up occasionally. EQV and IMP are rarely used in real applications and mostly appear in documentation or certification material — worth knowing they exist, not worth memorizing deeply.
writeOutput(true XOR false); // true writeOutput(true EQV true); // true writeOutput(true IMP false); // false
String Concatenation
The & operator joins strings together.
Ternary Operator
The ternary operator is a short way to write an if...else statement.
Syntax: condition ? value1 : value2
Operator Precedence
ColdFusion follows the standard order of operations: parentheses first, then multiplication/division, then addition/subtraction, then comparison, then logical operators.
Multiplication happens before addition, so this is 10 + (5 * 2), not (10 + 5) * 2.
Real-World Example
Common Beginner Mistakes
Using = instead of ==
if (age = 18) is a mistake carried over from other languages — in CFScript, = is assignment, not comparison. Write if (age == 18) to compare values.
Forgetting parentheses
10 + 5 * 2 evaluates to 20 because multiplication runs first. If you actually wanted addition first, write (10 + 5) * 2 instead, which gives 30.
Confusing & with +
Use & to join strings, like firstName & lastName. Using + instead can trigger unexpected numeric conversion errors, since + is for arithmetic.
Best Practices
- Use parentheses to improve readability, even when not strictly required.
- Use meaningful variable names.
- Keep expressions simple — split complex conditions across multiple lines or variables.
- Use & when joining strings, never +.
- Prefer word operators (EQ, LT, AND, etc.) in tag syntax for readability.
Interview Questions
What is an operator?
An operator performs an operation on one or more values (called operands).
Which operator joins strings?
The & operator.
Which operator returns the remainder after division?
The % (modulus) operator.
What is the difference between == and =?
= assigns a value to a variable, while == compares two values and returns true or false.
What does the ternary operator do?
It provides a shorter way to write a simple if...else statement, in the form condition ? value1 : value2.
What's the tag-syntax equivalent of CFScript's && and ||?
AND and OR. Tag syntax uses word operators (AND, OR, NOT, EQ, GT, LTE, and so on) instead of symbols.
Summary
In this lesson, you learned how operators work in ColdFusion. You explored arithmetic, assignment, comparison, logical, string, and ternary operators using both CFScript and Tag Syntax — including the word-based operators (EQ, GT, AND) that tag syntax uses in place of CFScript's symbols.
Understanding operators makes it much easier to write conditions, perform calculations, and build real-world ColdFusion applications.
What's Next?
The next lesson covers Output — how to display data using writeOutput() in CFScript and <cfoutput> in Tag Syntax, along with expressions, variables, and common output techniques.