W3Schools.com

JavaScript max() Method

Math Object Reference JavaScript Math Object

Definition and Usage

The max() method returns the number with the highest value.

Syntax

Math.max(x,y,z,...,n)

Parameter Description
x,y,z,...,n Optional. One or more numbers.
If no arguments are given, the result is -Infinity


Browser Support

Internet Explorer Firefox Opera Google Chrome Safari

The max() method is supported in all major browsers.


Example

Example

Return the number with the highest value:

<script type="text/javascript">

document.write(Math.max(5,10) + "<br />");
document.write(Math.max(0,150,30,20,38) + "<br />");
document.write(Math.max(-5,10) + "<br />");
document.write(Math.max(-5,-10) + "<br />");
document.write(Math.max(1.5,2.5));

</script>

The output of the code above will be:

10
150
10
-5
2.5

Try it yourself »


Math Object Reference JavaScript Math Object
WEB HOSTING
Best Web Hosting
PHP MySQL Hosting
Best Hosting Coupons
UK Reseller Hosting
Cloud Hosting
Top Web Hosting
$7.95/mo SEO Hosting
Premium Website Design
WEB BUILDING
XML Editor - Free Trial!
FREE Website BUILDER
Free Website Templates Free CSS Templates
Make Your Own Website
W3SCHOOLS EXAMS
Get Certified in:
HTML, CSS, JavaScript, XML, PHP, and ASP
W3SCHOOLS BOOKS
New Books:
HTML, CSS
JavaScript, and Ajax
STATISTICS
Browser Statistics
Browser OS
Browser Display
SHARE THIS PAGE