|| (logical OR)
Top  Previous  Next


SWiSH Player Support
SWF4 or later - Supported Internally

Syntax
expression1 || expression2

Arguments
expression1,expression2: A boolean value or an expression that converts to a Boolean value.

Returns
Logical result of expression1 OR expression2.

Description
Operator (logical); evaluates expression1 and expression2. The result is true if either or both expressions evaluate to true; the result is false only if both expressions evaluate to false. You can use the logical OR operator with any number of operands; if any operand evaluates to true, the result is true.

With non-boolean expressions, the logical OR operator causes the Flash Player to evaluate the expression on the left; if it can be converted to true, the result is true. Otherwise, it evaluates the expression on the right and the result is the value of that expression.

Sample
The following example uses the || operator in an if statement. The second expression evaluates to true, so the final result is true:
x = 10

y = 250

start = false
if(x > 25
 || y > 200 || start){
    trace('the logical OR test passed');
}


Sample
This example demonstrates how a non-boolean expression can produce an unexpected result. If the expression on the left converts to true, that result is returned without converting the expression on the right.
function fx1(){
    trace ("fx1 called");
    returns true;
}

function fx2(){
    trace ("fx2 called");
    return true;
}

if (fx1() || fx2()){
    trace ("IF statement entered");
}

// The following is sent to the 'Debug' window:

// fx1 called

// IF statement entered