JavaScript uses the and OR operator precedence to implement an if else condition judgment expression

Source: Internet
Author: User

<script type= "Text/javascript" >
/******************************************************************* implementing IfElse expressions with operator precedence
result = expression1 && expression2
Result is true when and only if the value of two expressions equals true.
If the value of either expression equals false, the result is false.
JScript uses the following rules to convert a non-Boolean value to a Boolean value:
All objects are considered true.
The string is considered false when and only if it is empty.
Null and undefined are considered false.
The number is false if and only if it is zero.
*******************************************************************/
alert (1&&0); False,return the first false ' s argument 0
alert (1&AMP;&AMP;2); True,return the last true ' s argument 2
/*******************************************************************
result = Expression1 | | Expression2
If one or two of the two expressions equals true, result is true.
JScript uses the following rules to convert non-Boolean values to Boolean values:
All objects are considered true.
The string is considered false when and only if it is empty.
Null and undefined are considered false.
The number is false if and only if it is 0 o'clock.
*******************************************************************/
Alert (1| | 0); True,return the first ture ' s argument 1
Alert (0| | FALSE); False,return the last false ' argument false
/*******************************************************************
A "side-by-side" expression that returns the last expression
*******************************************************************/
Alert ((1,0,-1)); Return the last Argument-1
/*******************************************************************
Use operator precedence to implement if (...) {...} Else{...}
The return value of the undefined is not clear.
Undefined,null will be converted to false.
*******************************************************************/
var a = true;
A && (alert (' true '), 1) | | Alert (' false ')
/*******************************************************************
Or use the three-mesh operator
*******************************************************************/
A? Alert (' True '): Alert (' false ');
</script>

JavaScript uses the and OR operator precedence to implement an if else condition judgment expression

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.