You can abuse the comma operator because it evaluates both of its operands and returns the second:
var x = this.checked ? y : doSomething(), doSomethingElse(), z;
However, this makes the code less readable (and supported) than the corresponding if
:
var x; if (this.checked) { x = y; } else { doSomething(); doSomethingElse(); x = z; }
Therefore, I would recommend using an if
in your case.
source share