CopyCode The Code is as follows: <SCRIPT type = "text/JavaScript">
/*************************************** * *************************** Use operator priority to implement ifelse expressions
Result = expression1 & expression2
If both expressions are true, result is true.
If the value of any expression is equal to false, result is false.
JScript uses the following rules to convert non-boolean values to boolean values:
All objects are considered true.
String is considered as false only when it is null.
Null and undefined values are regarded as false.
If and only if it is zero, the value is false.
**************************************** ***************************/
Alert (1 & 0); // false, return the first false's argument 0
Alert (1 & 2); // true, return the last true's argument 2
/*************************************** ****************************
Result = expression1 | expression2
If either of the two expressions is true, the result is true.
JScript uses the following rules to convert non-boolean values to boolean values:
All objects are considered true.
String is considered as false only when it is null.
Null and undefined values are regarded as false.
The value is false only when the value is 0.
**************************************** ***************************/
Alert (1 | 0); // true, return the first ture's argument 1
Alert (0 | false); // false, return the last false 'argument false
/*************************************** ****************************
Returns the last expression.
**************************************** ***************************/
Alert (1, 0,-1); // return the last argument-1
/*************************************** ****************************
Use the operator priority to implement if (...) {...} else {...}
Undefined is returned for all undefined returned values.
Undefined and null will be converted to false
**************************************** ***************************/
VaR A = true;
A & (Alert ('true'), 1) | alert ('false ')
/*************************************** ****************************
Or use the three-object Operator
**************************************** ***************************/
A? Alert ('true'): Alert ('false ');
</SCRIPT>