Math.min and Math.max

So here is a piece of code that I have seen used a lot but don’t really quite understand: :h:

myVar = Math.min(Math.max(myVar, this.min), this.max);

or some variation thereof. I understand that the function first finds the maximum value of two values then turns around and uses that to find the minimum between two values.

Can someone please expand on why this is done? And how do you know when to use it?

I have seen it used most often when scaling, for example.

Thanks all you genius Kirupians! :bu: