If you want to compare two numbers in Java Script, you can always use an if-else statement, but the Math object provides two methods that do that for you. The Math.max method returns the highest value, the Math.min method returns the lowest value.
Welcome to Bucaro TecHelp!

Bucaro TecHelp
Maintain Your Computer and Use it More Effectively
to Design a Web Site and Make Money on the Web

About Bucaro TecHelp About BTH User Agreement User Agreement Privacy Policy Privacy Site Map Site Map Contact Bucaro TecHelp Contact RSS News Feeds News Feeds

Victims of Sandy Hook

Stop the Slaughter of Innocents. Congress is bought and paid for by gun lunatics and gun promotion groups. If you want to live in a safe America, help buy Congress back for America. Send a donation to Mayors Against Illegal Guns, 909 Third Avenue, 15th Floor New York, NY 10022

Determine Minimum and Maximum

If you want to compare two numbers in Java Script, you can always use an if-else statement, but the Math object provides two methods that do that for you. The Math.max method returns the highest value, the Math.min method returns the lowest value.

var a = 5;
var b = 6;
var n = Math.max(a,b);

The code shown above declares two variables a, assigned as value of 5, and b, assigned as value of 6. When both variables are passed to Math.max method, it returns the value of the variable with the highest value (6).

var a = 5;
var b = 6;
var n = Math.min(a,b);

Similarly, When both variables are passed to Math.min method, it returns the value of the variable with the lowest value (5).

When you need to compare two numbers use the apropriate Java Script Math object max or min method.

RSS Feed RSS Feed



Follow Stephen Bucaro Follow @Stephen Bucaro


Web Design Sections

Fire HD
[Site User Agreement] [Privacy Policy] [Site map] [Search This Site] [Contact Form]
Copyright©2001-2016 Bucaro TecHelp 13771 N Fountain Hills Blvd Suite 114-248 Fountain Hills, AZ 85268