The three Logical operators are the logical AND , logical OR, and logical NOT. The symbol for AND is &&, the symbol for or is ||, and the symbol for NOT is !.
The && Operator (Logical AND)
If the expression on the left-hand side of the && evaluates to zero, null or the empty string "", the expression is false. If the expression on the left-hand side of the operator evaluates to true (non zero), then the right-hand side is evaluated, and if that expression is also true, then the whole expression is true. If the left-hand side evaluates to true, and the right-hand side is false, the expression is false. If evaluated as Booleans, the same rules apply, except the returned value will be either Boolean true or false.
The || Operator (Logical OR)
JavaScript uses the || symbol to represent the logical OR. If the expression on the left-hand side of the || operator is evaluated as true (non zero), the value of the expression is true, and no further checking is done. If the value on the left-hand side of the || operator is false, the value of the expression on the right-hand side of the operator is evaluated, and if true, the expression is true; that is, only one expression must be true. Once an expression returns true, the remaining expressions can be either true or false. It doesn't matter, as long as one expression is true.
The ! Operator (Logical NOT)
JavaScript provides the NOT (!) operator for negation. The ! operator is called a unarybecause it has only one operand; for example, ! true or !5. It returns true if the expression evaluates to false and returns false if the expression evaluates to true.
Syrell Calabag, signing off..
The && Operator (Logical AND)
If the expression on the left-hand side of the && evaluates to zero, null or the empty string "", the expression is false. If the expression on the left-hand side of the operator evaluates to true (non zero), then the right-hand side is evaluated, and if that expression is also true, then the whole expression is true. If the left-hand side evaluates to true, and the right-hand side is false, the expression is false. If evaluated as Booleans, the same rules apply, except the returned value will be either Boolean true or false.
The || Operator (Logical OR)
JavaScript uses the || symbol to represent the logical OR. If the expression on the left-hand side of the || operator is evaluated as true (non zero), the value of the expression is true, and no further checking is done. If the value on the left-hand side of the || operator is false, the value of the expression on the right-hand side of the operator is evaluated, and if true, the expression is true; that is, only one expression must be true. Once an expression returns true, the remaining expressions can be either true or false. It doesn't matter, as long as one expression is true.
The ! Operator (Logical NOT)
JavaScript provides the NOT (!) operator for negation. The ! operator is called a unarybecause it has only one operand; for example, ! true or !5. It returns true if the expression evaluates to false and returns false if the expression evaluates to true.
Syrell Calabag, signing off..
No comments:
Post a Comment