Convert if-else into conditional expression

Convert an if-else return or assignment expression into a conditional expression.

Convert if-else into conditional expression

Why is this refactoring helpful?

The evaluation of if-statements in JavaScript does not result in a value because they are statements, not expressions. In many situations, you might want to compute a value conditionally, and the conditional expression operator ? is a better fit. When you are familiar with conditional expressions, single-level conditional expressions are more concise and often easier to understand than if-else statements.


Related Code Assists

Learn More

Available In