Can we have more then one else if statement using the conditional shortcut.
var x = this.checked ? y : z;
You can abuse the comma operator, since it evaluates both its operands and returns the second one:
var x = this.checked ? y : doSomething(), doSomethingElse(), z;
However, that makes the code less readable (and maintainable) than the corresponding if
statement:
var x;
if (this.checked) {
x = y;
} else {
doSomething();
doSomethingElse();
x = z;
}
So I would recommend using an if
statement in your case.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With