Sunday, May 19, 2024
16
rated 0 times [  19] [ 3]  / answers: 1 / hits: 92474  / 12 Years ago, thu, july 19, 2012, 12:00:00

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"

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()

Is this possible at all?


More From » if-statement

 Answers
5

you can use && operator - second operand expression is executed only if first is true



direction == right && slideOffset += $(.range-slide).width()


in my opinion if(conditon) expression is more readable than condition && expression


[#84156] Wednesday, July 18, 2012, 12 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
madalynn

Total Points: 342
Total Questions: 95
Total Answers: 106

Location: Turkmenistan
Member since Sat, Apr 16, 2022
2 Years ago
;