Logical Operators

Top  Previous  Next

Operators:  &&  ||

Syntax:

expression1 && expression2

Logical AND

expression1 || expression2

Logical OR

 

The logical operators always evaluate expression1, but only evaluate expression2 if necessary.

 

For the logical AND operator &&, expression1 is converted to Boolean. If the result is true, then expression2 is evaluated.

 

For the logical OR operator ||, expression1 is converted to Boolean. If the result is false, then expression2 is evaluated.

 

The result of either operator is the last expression evaluated. If this is expression1, the result is the original value before the conversion to Boolean.