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

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

The ternary operator is the only operator in JavaScript that works with 3 operands, and it’s a short way to express conditionals.

三元运算符是JavaScript中唯一可以使用3个操作数的运算符,这是表达条件的一种简短方法。

This is how it looks:

看起来是这样的:

?
:

The condition <condition> is evaluated as a boolean, and upon the result, the operator runs the first expression (if the condition is true) or the second.

条件<condition>被评估为布尔值,并且根据结果,运算符将运行第一个表达式(如果条件为true)或第二个表达式。

This is an example: we check if running equals to true, and if this is the case we call the stop() function. Otherwise we call the run() function:

这是一个例子:我们检查,如果running等于真的,如果是这样的话,我们调用stop()函数。 否则,我们调用run()函数:

Example usage:

用法示例:

const running = true;(running === true) ? stop() : run()

翻译自:

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

你可能感兴趣的文章
About me
查看>>
gdbserver 移植与多线程调试
查看>>
乘法表
查看>>
非专业码农 JAVA学习笔记 用户图形界面设计与实现-所有控件的监听事件
查看>>
获取用户ip接口
查看>>
Django部署
查看>>
我与小娜(02):乘坐超速高铁,穿越时空60年
查看>>
H5取经之路——添加hover实现特定效果
查看>>
ultraiso:usb-hdd+ v2
查看>>
WINDOWS symbols
查看>>
SQL Server 2008 镜像的监控 - Joe.TJ -
查看>>
SQL Server DBA 文章:116篇 --DBA_Huangzj
查看>>
数据库Mysql性能优化
查看>>
程序猿是如何解决SQLServer占CPU100%的--马非码
查看>>
Shell之sed用法 转滴
查看>>
百度ueditor 拖文件或world 里面复制粘贴图片到编辑中 上传到第三方问题
查看>>
python基础之函数参数、嵌套、返回值、对象、命名空间和作用域
查看>>
公式推导【ASRCF//CVPR2019】
查看>>
Python(4)_Python中的数据类型
查看>>
HTTP 响应头信息
查看>>