javascript中的逻辑与或非

前端之家收集整理的这篇文章主要介绍了javascript中的逻辑与或非前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

javascript中的逻辑与或非

 

Examples
The following code shows examples of the && (logical AND) operator.

a1=true && true       // t && t returns true
a2=true && false      // t && f returns false
a3=false && true      // f && t returns false
a4=false && (3 == 4)  // f && f returns false
a5="Cat" && "Dog"     // t && t returns Dog
a6=false && "Cat"     // f && t returns false
a7="Cat" && false     // t && f returns false

 

The following code shows examples of the || (logical OR) operator.

o1=true || true       // t || t returns true
o2=false || true      // f || t returns true
o3=true || false      // t || f returns true
o4=false || (3 == 4)  // f || f returns false
o5="Cat" || "Dog"     // t || t returns Cat
o6=false || "Cat"     // f || t returns Cat
o7="Cat" || false     // t || f returns Cat

 

The following code shows examples of the ! (logical NOT) operator.

n1=!true              // !t returns false
n2=!false             // !f returns true
n3=!"Cat"             // !t returns false

 

 

http://www.webreference.com/javascript/reference/core_ref/ops.html

猜你在找的JavaScript相关文章