JavaScript中的问号和冒号 [英] Question mark and colon in JavaScript
本文介绍了JavaScript中的问号和冒号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我遇到以下行
hsb.s = max != 0 ? 255 * delta / max : 0;
是什么?
和:
在这种情况下是什么意思?
What do the ?
and :
mean in this context?
推荐答案
它的形式为:条件
? value-if-true
: value-if-false
想想?
asthen和:
aselse。
It has the form of: condition
? value-if-true
: value-if-false
Think of the ?
as "then" and :
as "else".
您的代码相当于
if (max != 0)
hsb.s = 255 * delta / max;
else
hsb.s = 0;
这篇关于JavaScript中的问号和冒号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文