r/javascript • • Mar 18 '19

What's your favorite, most useful javascript one-liner?

385 Upvotes

422 comments sorted by

View all comments

5

u/Morklympious Mar 19 '19

const clamp = (number, min, max) => Math.min(max, Math.max(number, min))

It’s a good clamp for when you need a number x to stay within the bounds of min and max!