
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
112
|
Chapter 5: Operators
var radius = 10;
var height = 25;
var circleArea = (Math.PI * radius * radius);
var cylinderVolume = circleArea * height;
Number of Operands
Operators are sometimes categorized according to how many operands they take (i.e.,
require or operate on). Some ActionScript operators take one operand, some take
two, and one even takes three:
–x // One operand
x * y // Two operands
(x = = y) ? "true result" : "false result" // Three operands
Single-operand operators are called unary operators; operators that take two oper-
ands are called binary operators; operators that take three operands are called ter-
nary operators. For our purposes, we’ll look at operators according to what they do,
not the number of operands they take.
Operator Precedence
Operators’ precedence determines which operation is performed first in an expres-
sion with multiple operators. For example, when multiplication and addition occur
in the same expression, multiplication is performed first:
4 + 5 * 6 // Yields 34, because 4 + 30 = 34
The expression 4+5* 6 is evaluated as 4+(5* 6) because the * operator has
higher precedence than the
+ operator. Similarly, when less-than (<) and concatena-
tion (
+) operators occur in the same expression, concatenation occurs first. For
example, this statement displays ...