Clamps a numeric value between an optional minimum and maximum bound.
The value to clamp.
The lower bound (inclusive). Defaults to -Infinity.
-Infinity
The upper bound (inclusive). Defaults to Infinity.
Infinity
value if it lies within [min, max], otherwise the nearest bound.
value
[min, max]
clamp(5, 0, 10); // 5clamp(-3, 0, 10); // 0clamp(15, 0, 10); // 10clamp(5); // 5 (no bounds) Copy
clamp(5, 0, 10); // 5clamp(-3, 0, 10); // 0clamp(15, 0, 10); // 10clamp(5); // 5 (no bounds)
Clamps a numeric value between an optional minimum and maximum bound.