什么是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 男友爷爷出院祝福语简短