Skip to content

unicorn/prefer-math-min-max Pedantic

🛠️ An auto-fix is available for this rule.

What it does

Prefers use of Math.min() and Math.max() instead of ternary expressions when performing simple comparisons for more concise, easier to understand, and less prone to errors.

Examples

Examples of incorrect code for this rule:

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

Examples of correct code for this rule:

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

References

Released under the MIT License.