Great article! Don't forget that && and || use short-circuit evaluation, useful for use cases like feature flags and set default values:
//if flag is true, then execute this functionprocess.env.FLAG&&someFunc();//Instead of...constvar2=var1?var1:"something";//...use || operatorconstvar2=var1||"something";
Great article! Don't forget that && and || use short-circuit evaluation, useful for use cases like feature flags and set default values:
Hi André! Thank you for your comment. With just some lines you have provided a great input about default values.
Yes!
As a reminder, the logical operators work the following way with non-boolean values:
expr1 && expr2: Ifexpr1is truthy, returnsexpr2; else, returnsexpr1.expr1 || expr2: Ifexpr1is truthy, returnsexpr1; else, returnsexpr2.