javascript - how can I turn my if else to a ternary -
i can't figure out how turn if else statement ternary
if (val === true && optval === 'car')view_list.style.visibility = 'hidden'; else view_list.style.visibility = 'visible';
view_list.style.visibility = (val === true && optval === 'car') ? 'hidden' : 'visible'; in ternary statement, have few different parts:
var = expression ? value_if_true : value_if_false
varoptional. don't have include if don't want worry assignment, in general ternaries used for.expressionexpression evaluate. boolean evaluation stored next part.value_if_trueused ifstatementtruthy.value_if_falseused ifstatementfalsey.
Comments
Post a Comment