博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
JavaScript逻辑运算符
阅读量:2505 次
发布时间:2019-05-11

本文共 1087 字,大约阅读时间需要 3 分钟。

JavaScript provides us 3 logical operators: and, or and not.

JavaScript的为我们提供了3个逻辑运算符:

逻辑与 (Logical and)

Returns true if both operands are true:

如果两个操作数都为true,则返回true:

&&

For example:

例如:

a === true && b > 3

The cool thing about this operator is that the second expression is never executed if the first evaluates to false. Which has some practical applications, for example, to check if an object is defined before using it:

关于此运算符的很酷的事情是,如果第一个表达式的计算结果为false,则永远不会执行第二个表达式。 它具有一些实际应用,例如,在使用对象之前检查是否已定义对象:

const car = { color: 'green' }const color = car && car.color

逻辑或 (Logical or)

Returns true if at least one of the operands is true:

如果至少一个操作数为true,则返回true:

||

For example:

例如:

a === true || b > 3

This operator is very useful to fallback to a default value. For example:

该运算符对于回退到默认值非常有用。 例如:

const car = {}const color = car.color || 'green'

makes color default to green if car.color is not defined.

如果car.color color默认为green

逻辑不(!) (Logical not (!))

Invert the value of a boolean:

反转布尔值:

let value = true!value //false

翻译自:

转载地址:http://rtqgb.baihongyu.com/

你可能感兴趣的文章
python 计时程序运行时间
查看>>
Git学习系列-Git基本概念
查看>>
c#多个程序集使用app.config 的解决办法
查看>>
Linux+Apache+PHP+MySQL服务器环境配置(CentOS篇)
查看>>
Linux下获取本机IP地址的代码
查看>>
(C#)调用Webservice,提示远程服务器返回错误(500)内部服务器错误
查看>>
flex布局
查看>>
python-----python的文件操作
查看>>
java Graphics2d消除锯齿,使字体平滑显示
查看>>
控件中添加的成员变量value和control的区别
查看>>
Spring Boot Docker 实战
查看>>
Div Vertical Menu ver3
查看>>
Git简明操作
查看>>
InnoDB为什么要使用auto_Increment
查看>>
课堂练习之买书打折最便宜
查看>>
定义函数
查看>>
网络虚拟化技术(二): TUN/TAP MACVLAN MACVTAP
查看>>
MQTT协议笔记之mqtt.io项目HTTP协议支持
查看>>
(转)jQuery中append(),prepend()与after(),before()的区别
查看>>
Tecplot: Legend和图像中 Dashed/Dash dot/Long dash 等虚线显示没有区别的问题
查看>>