什么是JavaScript中的逻辑运算符?
JavaScript支持以下逻辑运算符。假设变量A持有10,变量B持有20,那么,
如果两个操作数都不为零,则条件变为true。
例如:(A&&B)是真的。
如果两个操作数中的任何一个都不为零,则条件变为true。
例如:(A||B)为真。
反转其操作数的逻辑状态。如果条件为真,则逻辑非运算符会将其设置为假。
例如: !(A&&B)是错误的。
示例
您可以尝试以下代码来学习如何在JavaScript中实现逻辑运算符-
<html>
<body>
<script>
<!--
var a = true;
var b = false;
var linebreak = "<br />";
document.write("(a && b) => ");
result = (a && b);
document.write(result);
document.write(linebreak);
document.write("(a || b) => ");
result = (a || b);
document.write(result);
document.write(linebreak);
document.write("!(a && b) => ");
result = (!(a && b));
document.write(result);
document.write(linebreak);
//-->
</script>
<p>Set the variables to different values and different operators and then try...</p>
</body>
</html>热门推荐
10 香港老妈结婚祝福语简短
11 毕业立体贺卡祝福语简短
12 简短新年年会祝福语
13 评论小品祝福语大全简短
14 恭喜师兄结婚祝福语简短
15 员工集体辞职祝福语简短
16 高中新生祝福语 简短
17 装修祝福语男生搞笑简短
18 生日开业蛋糕祝福语简短