One line if/else in JavaScript -
this question has answer here:
i have logic switches(with , else/if) true/false on/off make more condensed , not use switch statement. ideally if/else converted 1 short line. thank you!!!
var properties = {}; var isitmuted = scope.slideshow.ismuted(); if (isitmuted === true) { properties['value'] = 'on'; } else { properties['value'] = 'off'; }
you want ternary operator:
properties['value'] = (isitmuted === true) ? 'on' : 'off';
the ? :
called ternary operator , acts if
/else
when used in expression.
Comments
Post a Comment