Is it possible to execute multiple actions within a ternary condition? Something similar to the following (which does not work):
condition ? () => {
    // Perform multiple actions within this delegate function if the condition is true
} : // Perform an action if the condition is false;
If you want to do this with a single function, it's simple:
condition ? console.log("true") : console.log("false");
If you want multiple functions to be called, it's a bit more complex:
condition 
    ? (() => {
        console.log("true");
        console.log("still true");
    })()
    : (() => {
        console.log("false");
        console.log("still false")
    })();
This is because when you have a ternary, it will immediately invoke whatever is inside the block. So if you want to call a function, you need to execute that function with ().
Personally, though, I would recommend against this. I think it is much less clear than:
if (condition) {
    console.log("true");
    console.log("still true");
} else {
    console.log("true");
    console.log("still true");
}
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