Operators are used to compare and evaluate variables and expressions in our code. Operators play a very important part in programming. Without them not much would get done automatically. In the following example we use the ( == ) operator to check if a variable is equal to our literal value.
var myName:String = "Adam";
trace(myName == "Joe"); // Returns value of false
Some operators take precedence over others even if the other is the first expression, demonstrated here.
var equation:uint = 4 + 1 * 5;
trace(equation); // output is 9 not 25, multiplication performs first
Reference Chart for Commonly Used Operators in Actionscript 3.0
| Operator |
Operation |
| = |
The assignment operator. Used primarily to place values into variables. |
| ++ |
Increments a value. If placed in front of variable name, it increments then returns value. If placed after the variable it returns the value of variable first then increments. |
| -- |
Decrements a value. If placed in front of variable name, it decrements then returns value. If placed after the variable it returns the value of variable first then decrements. |
| + |
Addition on numbers and combining of strings. |
| - |
Subtraction on numbers, and defines a negative value. |
| * |
Multiplication |
| / |
Division |
| % |
Modulo |
| < |
Less than |
| > |
Greater than |
| <= |
Less than or equal to |
| >= |
Greater than or equal to |
| == |
Equal |
| != |
Not equal |
| === |
Strict equality |
| !== |
Strict inequality |
| && |
Logical AND |
| || |
Logical OR |
| ?: |
Conditional |