Pattern: Ternary expression for min/max comparison
Issue: -
Using Math.min()
and Math.max()
functions provides a more concise and clearer way to handle value boundaries compared to ternary expressions, making the code easier to understand and less prone to errors.
Example of incorrect code:
height > 50 ? 50 : height;
height > 50 ? height : 50;
Example of correct code:
Math.min(height, 50);
Math.max(height, 50);