Compare operation returns a single result, true or false. A plurality of logical operation may be operating together for comparison compare.
Operators
Series operator | name | Explanation |
&& | Logic and | A plurality of inspection conditions, if the conditions checked are true returns true |
|| | Logical or | A plurality of inspection conditions if any of the conditions to be checked are true returns true |
! | Logical NOT | Boolean value inversion |
Logic and
1 true && true //返回true
2 to true && false // returns false
3 false to true && // returns false
4 false && false // returns false
Logical or
1 returns true true || true //
2 returns true true || false //
3 returns true false || true //
4 false || false // returns false
Logical NOT
1
2
|
!
true
//
返回
false
!
false
//
返回
true
|
Short-circuit conditions
Logical expression left to right. If the first condition to provide sufficient information for the final result, there is no requirement that the latter calculation.
1
|
false
&& 任何条件
|
Here is false, it is not necessary at this time to go back calculation expression, because the entire result can not be true.
1
|
true
&& 任何条件
|
Here is true, it is not necessary at this time to go back calculation expression, as it has at least one result is true.
Example:
1 <!DOCTYPE HTML> 2 <html lang="zh"> 3 <body> 4 <script> 5 document.write(3>2 && 3<2);//逻辑与(必须都为true,否则为false) 6 document.write('<br>'); 7 document.write(7>3 && 7>4); 8 document.write('<br>'); . 9 document.write ( . 3 * . 4 == . 4 * . 3 || 2 * . 5 == . 4 * . 5 ); // logical OR (wherein a is true, compared to true) 10 document.write ( ' <br> ' ); . 11 document.write ( . 7 < . 3 || . 7 < . 4 ); 12 is document.write ( ' <br> ' ); 13 is document.write ( ! . 7 > . 3 ); //The logical negation value of the Boolean negation 14 </ Script > 15 </ body > 16 </ HTML >