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

  • var optional. don't have include if don't want worry assignment, in general ternaries used for.
  • expression expression evaluate. boolean evaluation stored next part.
  • value_if_true used if statement truthy.
  • value_if_false used if statement falsey.

Comments

Popular posts from this blog

javascript - jquery or ashx not working -

opencv - DataType<cv::detail::deriv_type>::depth what is it used for -

python 3.x - Mapping specific letters onto a list of words -