Whatever message this page gives is out now! Go check it out!
12
MyVariable
a++
(1 + 1)/2
"father" & "Mother"
Form.divisor/Form.dividend
Round(3.14159)Expression Operator ExpressionOperator | Description |
+ - * / | Basic arithmetic: Addition, subtraction, multiplication, and division. In division, the right operand cannot be zero. |
++ – | Increment and decrement. Increase or decrease the variable by one.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. |
+= -= *= /= %= | Compound assignment operators. The variable on the right is used as both an element in the expression and the result variable. Thus, the expression a += b is equivalent to a = a +b. An expression can have only one compound assignment operator. |
+ - | Unary arithmetic: Set the sign of a number. |
MOD or % | Modulus: Return the remainder after a number is divided by a divisor. The result has the same sign as the divisor. The value to the right of the operator should be an integer; using a non-numeric value causes an error, and if you specify a real number, ColdFusion ignores the fractional part (for example, 11 MOD 4.7 is 3). |
\ | Integer division: Divide an integer by another integer. The result is also an integer; for example, 9\4 is 2. The right operand cannot be zero. |
^ | Exponentiation: Return the result of a number raised to a power (exponent). Use the caret character (^) to separate the number from the power; for example, 2^3 is 8. Real and negative numbers are allowed for both the base and the exponent. However, any expression that equates to an imaginary number, such -1^.5 results in the string "-1.#IND. ColdFusion does not support imaginary or complex numbers. |
Operator | Description |
+= | Addition assignment: Adds the value of the right operand to the variable and assigns the result to the variable. For example, |
<cfscript>
a=3;
b=2;
while((a+=b)< 10)
{
b +=2;
writeOutput("a=" &a&"<br/>");
writeOutput("b=" &b&"<br/>");
}
</cfscript>Output a=5 b=4 a=9 b=6 | |
-= | Subtraction assignment: Subtracts the value of the right operand from the variable and assigns the result to the variable. For example, |
<cfscript>
a=5;
b=2;
while((a-=b)> 2)
{
b-=1;
writeOutput("a=" &a&"<br/>");
writeOutput("b="&b&"<br/>");
}
</cfscript>Output a=3 b=1 | |
*= | Multiplication assignment: Multiplies the variable by the value of the right operand and assigns the result to the variable. For example, |
<cfscript>
a=3;
b=2;
while((a*=b)<7)
{
b*=1;
writeOutput("a=" &a&"<br/>");
writeOutput("b=" &b&"<br/>");
}
</cfscript>Output a=6 b=2 | |
/= | Division assignment: Divides the variable by the value of the right operand and assigns the result to the variable. For example, |
<cfscript>
a=3;
b=2;
while((a/=b)==1.5)
{
writeOutput(a&"<br/>");
}
</cfscript>Output 1.5 | |
%= | Modulus assignment: Calculates the remainder of division between two numbers and assigns the result to the left operand. |
<cfscript>
a=7
b=5
a%=b
writeOutput("%=<br/>")
writeOutput(a)
</cfscript>Output %= 2 |
Operator | Description |
NOTor ! | Reverse the value of an argument. For example, NOT True is False and the inverse. |
AND or && | Return True if both arguments are True; return False otherwise. For example, True AND True is True, but True AND False is False. |
OR or || | Return True if any of the arguments is True; return False otherwise. For example, True OR False is True, but False OR False is False. |
XOR | Exclusive or: Return True if one of the values is True and the other is False. Return False if both arguments are True or both are False. For example, True XOR True is False, but True XOR False is True. |
EQV | Equivalence: Return True if both operands are True or both are 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: The statement A IMP B is the equivalent of the logical statement "If A Then B." A IMP B is False only if A is True and B is False. It is True in all other cases. |
Operator | Description |
IS EQUAL EQ | Perform a case-insensitive comparison of two values. Return True if the values are identical. |
IS NOT NOT EQUAL NEQ | Opposite of IS. Perform a case-insensitive comparison of two values. Return True if the values are not identical. |
CONTAINS | Return True if the value on the left contains the value on the right. |
DOES NOT CONTAIN | Opposite of CONTAINS. Return True if the value on the left does not contain the value on the right. |
GREATER THAN GT | Return True if the value on the left is greater than the value on the right. |
LESS THAN LT | Opposite of GREATER THAN. Return True if the value on the left is smaller than the value on the right. |
GREATER THAN OR EQUAL TO GTE GE | Return True if the value on the left is greater than or equal to the value on the right. |
LESS THAN OR EQUAL TO LTE LE | Return True if the value on the left is less than or equal to the value on the right. |
123.45 CONTAINS 3.4 |
"a" IS "A" |
"abde" LT "ac" |
Operator | Description |
& | Concatenates strings. |
&= | Compound concatenation. The variable on the right is used as both an element in the concatenation operation and the result variable. Thus, the expression a &= b is equivalent to a = a & b.An expression can have only one compound assignment operator. |
(Boolean expression)? expression1 : expresson2<cfset c = (a GT b)? a : b >^
*, /
\
MOD
+, -
&
EQ, NEQ, LT, LTE, GT, GTE, CONTAINS, DOES NOT CONTAIN, ==, !=, >, >=, <, <=
NOT, !
AND, &&
OR, ||
XOR
EQV
IMPUsage | Example |
No arguments | Function() |
Basic format | Function(Data) |
Nested functions | Function1(Function2(Data)) |
Multiple arguments | Function(Data1, Data2, Data3) |
String arguments | Function('This is a demo')Function(This is a demo) |
Arguments that are expressions | Function1(X*Y, Function2("Text")) |
<cfset myDate = DateFormat(Now(), "mmmm d, yyyy")>Abs(Myvar)/Round(3.14159)<cfset myStringVar = UCase(firstVariable & " more sleep!")>a=b=c=d*5//The following line is valid.
var a = var b = c = d*5
//The following line is not valid.
// a = b = var c = d*5map()<cfscript>
result = [1,2,3,4].map(function(value) {
return value * 2;
});
writeDump(result)
// Result: [2,4,6,8]
</cfscript>filter()<cfscript>
filtered = [1,2,3,4,5].filter(function(value) {
return value > 2;
});
writeDump(filtered);
// Result: [3,4,5]
</cfscript>reduce()<cfscript>
sum = [1,2,3,4].reduce(function(acc, val) {
return acc + val;
}, 0);
writeOutput(sum)
// Result: 10
</cfscript><cfscript>
result = [1,2,3,4,5].filter(function(v) {
return v > 2;
}).map(function(v) {
return v * 2;
}).sort("numeric");
// Result: [6,8,10]
writeDump(result)
</cfscript><cfscript>
len = [[1,2], [3,4]][1].len();
// Result: 2
writeOutput(len);
</cfscript>keyArray()<cfscript>
keys = {"a"=1, "b"=2, "c"=3}.keyArray();
// Result: ["a","b","c"]
writeDump(keys);
</cfscript>filter()<cfscript>
result = {"a"=1, "b"=2, "c"=3}.filter(function(key, value) {
return value > 1;
});
// Result: {"b"=2, "c"=3}
writeDump(result);
</cfscript><cfscript>
[1,2,3,4].each(function(v) {
writeOutput(v & " ");
});
// Output: 1 2 3 4
</cfscript><cfscript>
// e.g. 1 === "1" is false, but 1 === 1 is true
function returntrue(){
return true
}
writeoutput(returntrue() == 'true'); // YES
writeoutput(returntrue() == TRUE); // YES
writeoutput(returntrue() === 'true'); // NO
writeoutput(returntrue() === true); // YES
writeoutput(returntrue() === TRUE); // YES
</cfscript><cfscript>
writedump(2=="2"); // YES
writedump(2==="2"); // NO
writedump('yes' == 1); // YES
writedump('yes' === 1); // NO
writedump(false ==0); // YES
writedump(false ===0);//NO
</cfscript><cfscript>
writedump(2!="2"); // NO
writedump(2!=="2"); // YES
writedump('yes' != 1); // NO
writedump('yes' !== 1);// YES
writedump(false !=0); // NO
writedump(false !==0);//YES
</cfscript><cfscript>
numbers = [1,2,3];
writeDump(sum( ...numbers ));
function sum(required x,required y,required z) {
return x + y + z;
}<cfscript>
myarray1=[5,6,7]
myarray2=[3,4,5,...myarray1]
myarray3=[1,2,3,...myarray2]
writedump(myarray3)
</cfscript><cfscript>
beatles={
"vocals":"John Lennon",
"guitar":"George Harrison",
"bass":"Paul McCartney",
"drums":"Ringo Starr"
}
beatlesCopy={...beatles,'justanotherkey':'justanothervalue'}
writeDump(beatlesCopy)
</cfscript><cfscript>
numbers = [1,2,3]
list = [...numbers, '4', 'five', 6,...numbers]
writeDump(list)
</cfscript><cfscript>
arr = [..."12345","foo",..."bar",..."123"];
writeDump(arr)
</cfscript><cfscript>
obj1 ={ foo: 'bar', x: 42 };
obj2 ={ foo: 'baz', y: 13 };
newObj = {...obj1,...obj2};
writeDump(newObj)
</cfscript><cfscript>
s1=["Mick Jagger"]
s2=["Keith Richards","Ron Wood"]
s3=["Charlie Watts"]
// merge the arrays using Spread
stones=[...s1,...s2,...s3]
writeDump(stones)
</cfscript><cfscript>
s1=["Mick Jagger"]
s2=["Keith Richards","Ron Wood"]
s3=["Charlie Watts"]
// merge the arrays using Spread
stones=["Brian Jones","Bill Wyman",...s1,...s2,...s3]
writeDump(stones)
</cfscript><cfscript>
foo={
"key1":"val1",
"key2":"val2",
"key3":"val3"
}
bar={
"key4":"val4",
"key5":"val5"
}
combo={...foo,...bar}
writeDump(combo)
</cfscript><cfscript>
foo={
"key1":"val1",
"key2":"val2",
"key3":"val3"
}
bar={
"key3":"val4",
"key5":"val5"
}
combo={...foo,...bar}
writeDump(combo)
</cfscript><cfscript>
function calcVolume(width, height, depth) {
writeOutput(width * height * depth)
}
calcVolume(12, 30, 14) // the usual way
cube = [12, 30, 14]
// using Spread operator
calcVolume(...cube)
</cfscript><cfscript>
function myRest(...args){
writeDump(args)
}
myRest(1,2,3,4,5)
</cfscript><cfscript>
function myFun(a,b,...otherArgs){
writeOutput(serializeJSON(a))
writeOutput(serializeJSON(b))
writeOutput(serializeJSON(otherArgs))
}
myFun("one","two","three","four","five","six","seven","eight")
</cfscript><cfscript>
function restTest(one,two,...args){
writeDump(one)
writeDump(two)
writeDump(args)
}
restTest(1,2,3,4,5)
</cfscript>