How to execute multiple functions in ternary operator

🦄 Option 1: Create each function and use comma

1
2
3
4
5
6
7
8
9
10
11
const flag1 = true;

const func1 = () => {
const funcOne = () => console.log('ONE');
const funcTwo = () => console.log('TWO');
const funcThree = () => console.log('THREE');

flag1 ? (funcOne(), funcTwo()) : funcThree();
};

func1(); // ONE TWO

🦄 Option 2: Use Immediately-Invoked Function Expression (IIFE)

1
2
3
4
5
6
7
8
9
10
11
12
const flag2 = true;

const func2 = () => {
flag2
? (() => {
console.log('ONE');
console.log('TWO');
})()
: console.log('THREE');
};

func2(); // ONE TWO