Table of Contents

Math.min( ) Method Flash 5; can be used when exporting Flash 4 movies

determine the smaller of two numbers
Math.min(x, y)

Arguments

x

A number.

y

A number.

Returns

The smaller of x and y.

Description

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.

Example

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.

See Also

Math.abs( ), Math.max( )


Table of Contents