logical operators in PHP and JavaScript && and | | The comparison

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.