javascript简写if语句,没有else部分 [英] javascript shorthand if statement, without the else portion
本文介绍了javascript简写if语句,没有else部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
所以我正在使用简写的javascript 如果
/ else
语句(我在某地读到它们叫做Ternary语句?)
So I'm using a shorthand javascript if
/else
statement (I read somewhere they're called Ternary statements?)
this.dragHandle.hasClass('handle-low')? direction =left:direction =right
这很好用,但如果以后我只想使用简写 if
,没有 else
部分。喜欢:
This works great, but what if later I want to use just a shorthand if
, without the else
portion. Like:
direction ==right? slideOffset + = $(。range-slide)。width()
这可能吗?
推荐答案
你可以使用&&
运算符 - 第二个操作数表达式只有在第一个是true
you can use &&
operator - second operand expression is executed only if first is true
direction == "right" && slideOffset += $(".range-slide").width()
在我看来 if(conditon)表达式
比 condition&&表达式
这篇关于javascript简写if语句,没有else部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文