Conditional Operator in ActionScript
Notes:
Conditional Operator in ActionScript Programming Language:
Conditional Operator (?:): is the only ternary operator in Action Script. It accepts 3 operands.
(operand1) ? operand2 : operand3;
Where:
operand1: should be a condition
operand2: value1
operand3: value2
Ex:
trace("Conditional operator demo");
var num:int=20;
var result:String = ((num%2)==0)? "even" : "odd";
trace(num,"is",result,"number");
Note: Conditional operator is kind of short hand notation for if else statement in Action Script.
Ex:
var num:int=5;
var result:String="";
if((num%2)==0)
{
result = "even";
}
else
{
result = "odd";
}
trace(num,"is",result,"number");