condition ? exec1() : exec2;
or just one function: condition ? exec1() : null;
condition ? exec1() : null;
or condition ? exec1() : 0;
condition ? exec1() : 0;
You can optimize even more by using the && operator. Example: condition && exec1();
condition ? exec1(); exec2(); : 0;
condition ? exec1(); exec2(); : 0;
is wrong.condition ?
(function() {
exec1();
exec2();
})()
:0;
condition ? exec1() && exec2() && exec3() : 0;
condition ? exec1() && exec2() && exec3() : 0;
much more compact, but alas, it has a major drawback: if one of the executed functions returns false, the interpreter stops the execution of the following, the same problem will arise if you use the operator ||, the interpreter will stop at the first true result.condition ? exec1() | exec2() | exec3() : 0;
condition ? exec1() | exec2() | exec3() : 0;
or condition && ( exec1() | exec2() | exec3() );
condition ? ( exec1() , exec2() , exec3() ) :0;
Source: https://habr.com/ru/post/13388/
All Articles