One line if/else in JavaScript -


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

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -