Open this example in the interactive library
Source code
const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
console.log(clamp(120, 0, 100));
Sample output
100

Clamp within bounds. A self-contained example using the JavaScript runtime.
Open this example in the interactive library
const clamp = (n, min, max) => Math.min(max, Math.max(min, n));
console.log(clamp(120, 0, 100));
100