Operators

Operators combine subexpressions to create complex expressions. Operators act on the operands. The general syntax for using operators is:

Expression Operator Expression

ColdFusion has four types of operators:

Functions also can be viewed as operators because they act on operands.

Arithmetic operators

The arithmetic operators are shown in the following table.
Operator
Description
+  -  *  /
The basic arithmetic operators: addition, subtraction, multiplication, and division. In division, the right operand cannot be zero.
+  -
Unary arithmetic operators for setting the sign of a number.
MOD
Returns the remainder (modulus) after a number is divided by a divisor. The result has the same sign as the divisor. The right operand cannot be zero. For example, 11 MOD 4 is 3.
\
Divide an integer by another integer. Use the \ (trailing slash) to separate the integers. The right operand cannot be zero. For example, 9 \ 4 is 2.
^
Returns the result of a number raised to a power (exponent). Use the ^ (caret) to separate the number from the power. The left operand cannot be zero. For example, 2 ^ 3 is 8.

Boolean operators

Boolean, or logical, operators perform logical connective and negation operations. The operands of Boolean operators are Boolean (TRUE/FALSE) values.
Operator
Description
NOT
Reverses the value of an argument. For example, NOT TRUE is FALSE and vice versa.
AND
Returns TRUE if both arguments are TRUE; returns FALSE otherwise. For example, TRUE AND TRUE is TRUE, but TRUE AND FALSE is FALSE.
OR
Returns TRUE if any of the arguments is TRUE; returns FALSE otherwise. For example, TRUE OR FALSE is TRUE, but FALSE OR FALSE is FALSE.
XOR
Exclusive or-either, or, but not both. Returns TRUE if the truth values of both arguments are different; returns FALSE otherwise. For example, TRUE XOR TRUE is FALSE, but TRUE XOR FALSE is TRUE.
EQV
Equivalence both true or both false. The EQV operator is the opposite of the XOR operator. For example, TRUE EQV TRUE is TRUE, but TRUE EQV FALSE is FALSE.
IMP
Implication. A IMP B is the truth value of the logical statement "If A Then B." A IMP B is FALSE only when A is TRUE and B is FALSE.

Decision operators

ColdFusion's decision, or comparison, operators produce a Boolean TRUE/FALSE result. The decision operators are shown in the following table.
Operator
Description
IS
Performs a case-insensitive comparison of two values. Returns true if the values are identical.
IS NOT
Opposite of is.
CONTAINS
Determines whether the value on the left is contained in the value on the right. Returns true if it is.
DOES NOT CONTAIN
Opposite of contains.
GREATER THAN
Determines whether the value on the left is greater than the value on the right. Returns true if it is.
LESS THAN
Opposite of greater than.
GREATER THAN OR EQUAL TO
Determines whether the value on the left is greater than or equal to the value on the right. Returns true if it is.
LESS THAN OR EQUAL TO
Determines whether the value on the left is less than or equal to the value on the right. Returns true if it is.

Shorthand notation for decision operators

You can replace some decision operators with shorthand notations to make your CFML more compact, as shown in the following table.
Operator
Alternative name(s)
IS
EQUAL, EQ
IS NOT
NOT EQUAL, NEQ
GREATER THAN
GT
LESS THAN
LT
GREATER THAN OR EQUAL TO
GTE, GE
LESS THAN OR EQUAL TO
LTE, LE

String operators

There is one string operator, which is the concatenation operator.
Operator
Description
&
Concatenates strings.

Operator precedence

The order of precedence controls the order in which operators on the same line are evaluated. The order of precedence is shown below:

Unary +, Unary -

^

*, /

\

MOD

+, -

&

EQ, NEQ, LT, LTE, GT, GTE, CONTAINS, DOES NOT CONTAIN

NOT

AND

OR

XOR

EQV

IMP

To enforce a non-standard order of evaluation, you must parenthesize expressions. For example:

Parenthesized expressions can be nested. When in doubt about the order in which operators in an expression will be evaluated, use parentheses.



Banner.Novgorod.Ru