Math.min( ) Method | Flash 5; can be used when exporting Flash 4 movies |
determine the smaller of two numbers |
A number.
A number.
The smaller of x and y.
The min( ) function compares two numbers and returns the smaller of the two. When comparing two negative numbers, the one with a larger absolute value is actually smaller (see the following Example). If used on strings, min( ) returns NaN.
Math.min(5, 1); // Returns 1 Math.min(-6, -5); // Returns -6 Math.min(Math.abs(-6), Math.abs(-5)); // Returns 5
Reader Exercise: Modify the example under Math.max( ) to return the minimum value in an array rather than the maximum.