Skip to content

Files

Latest commit

 

History

History
21 lines (15 loc) · 495 Bytes

prefer-math-min-max.md

File metadata and controls

21 lines (15 loc) · 495 Bytes

Pattern: Ternary expression for min/max comparison

Issue: -

Description

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.

Examples

Example of incorrect code:

height > 50 ? 50 : height;
height > 50 ? height : 50;

Example of correct code:

Math.min(height, 50);
Math.max(height, 50);