I have a if else short statement as follows:
(one == two) ? "do this" : "do this"
Is there anyway to add an if else into this statement?
I can't seem to find anything with an if else...
I'm being specific to the short statement, as opposed to do if if else else longhand.
Thanks.
If you want to convert something like:
if(A) {
return X;
}
else if(B) {
return Y;
}
else {
return Z;
}
You can write this as:
A ? X : (B ? Y : Z);
You thus write the else if as a condition in the else-part (after :) of the upper expression.
However, I would strongly advice against too much cascading. The code becomes extremely unreadable and the ? : code structure was never designed for this.
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