DevLearningTools

🚧 This site is under active construction — new tools, guides, and pages are added every week.

MODULE 2 · LESSON 04

Operators

Arithmetic, assignment, comparison, logical, string, and ternary operators in ColdFusion — including the CFML tag-syntax word operators (EQ, GT, AND) versus CFScript symbols (==, >, &&).

New lessons are added one at a time as the course gets built out — a graded quiz for each lesson is still on the way.

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., +.
expression
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
NOTE

Here, 10 and 20 are operands, and + is the operator.

Types of Operators

ColdFusion provides several categories of operators.

CategoryPurpose
ArithmeticMathematical calculations
AssignmentAssign values
ComparisonCompare values
LogicalCombine conditions
StringJoin text
TernaryShort if...else

Arithmetic Operators

Arithmetic operators perform mathematical calculations.

OperatorDescriptionExample
+Addition10 + 5
-Subtraction10 - 5
*Multiplication10 * 5
/Division10 / 5
%Modulus (Remainder)10 % 3
CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

Assignment Operator

The assignment operator (=) stores a value in a variable.

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

Comparison Operators

Comparison operators compare two values and always return either true or false.

OperatorMeaning
==Equal
!=Not Equal
>Greater Than
<Less Than
>=Greater Than or Equal
<=Less Than or Equal
CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
NOTE

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.

PurposeTag Syntax (CFML)CFScript
EqualEQ, IS, EQUAL==
Not EqualNEQ, IS NOT, NOT EQUAL!=
Greater ThanGT, GREATER THAN>
Less ThanLT, LESS THAN<
Greater Than or EqualGTE>=
Less Than or EqualLTE<=
ContainsCONTAINSuse contains() or find()
Does Not ContainDOES NOT CONTAINuse !contains() or find() == 0

String Comparison

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

String Contains

Tag syntax has a dedicated CONTAINS operator. CFScript doesn't — use a string function like contains() or find() instead.

Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
NOTE

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.

PurposeTag Syntax (CFML)CFScript
Logical ANDAND&&
Logical OROR||
Logical NOTNOT!
Logical XOR (Exclusive OR)XORXOR
Logical EQV (Equivalent)EQVEQV
Logical IMP (Implication)IMPIMP

AND

Returns true only if both conditions are true.

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

OR

Returns true if at least one condition is true.

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

NOT

Reverses a Boolean value.

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

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.

CFScript
writeOutput(true XOR false); // true
writeOutput(true EQV true);  // true
writeOutput(true IMP false); // false

String Concatenation

The & operator joins strings together.

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

Ternary Operator

The ternary operator is a short way to write an if...else statement.

Syntax: condition ? value1 : value2

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

Operator Precedence

ColdFusion follows the standard order of operations: parentheses first, then multiplication/division, then addition/subtraction, then comparison, then logical operators.

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
NOTE

Multiplication happens before addition, so this is 10 + (5 * 2), not (10 + 5) * 2.

Real-World Example

CFScript
Simulated output — illustrative only, not a live ColdFusion/Lucee server.
Tag Syntax
Simulated output — illustrative only, not a live ColdFusion/Lucee server.

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.