Almost all languages have && (and) and | | (or) The logical operator,&& is used to judge multiple expressions, if true, continues to determine the next expression, if False (false), stops the expression parsing, which returns true only if all the expressions are true (true), If an expression is False (false), the result is (false); (or) on the contrary, it is also the case that multiple expressions are judged sequentially, and if the expression is true, the logical judgment of the terminating expression is true (true). Both of these logical operators have a short-circuit behavior:
&& evaluates the expression and, if true, continues the logical judgment, as long as false (false) stops the subsequent logic directly and returns FALSE.
|| Judge the expression, if false, continue to judge, as long as true (true) immediately stop judging the subsequent logic, return true.
In JavaScript and other programming languages (PHP), the difference between logical operators:
Returns the result value of the current terminating expression (possibly Boolean, string, number, and so on) after being judged by a logical operator in JavaScript
var num = True && 4 && "aaaaaa"; alert (num) //result is Aaaaaavar num = false | | 4 | | "AAAAAA" alert (num) //result is 4
after being judged by a logical operator in PHP, the returned result is only bool
$num = True && 4 && "aaaaaa"; echo $num; //result = True$num = False | | 4 | | "Aaaaaa" echo $num; //result is true
logical operators in PHP and JavaScript && and | | The comparison