Easy Tutorial
❮ Prop Canvas Linecap Prop Element Offsetwidth ❯

JavaScript max() Method

JavaScript Math Object

Example

Returns the larger of two specified numbers:

Output result:


Definition and Usage

The max() method returns the larger of two specified numbers.


Browser Support

All major browsers support the max() method.


Syntax

Parameter Values

Parameter Description
n1, n2, n3,...,nX Optional. One or more values. Prior to ECMAScript v3, this method only accepted two parameters.

Return Value

Type Description
Number The largest value among the arguments. If no arguments are given, it returns -Infinity. If any argument is NaN, or if a non-numeric value cannot be converted to a number, it returns NaN.

Technical Details

| JavaScript Version: | 1.0 | | --- | --- |


More Examples

Example

In this example, we will demonstrate how to use max() to return the highest value among specified numbers:

a, b, c, d, and e output result:

10
150
10
-5
2.5

JavaScript Math Object

❮ Prop Canvas Linecap Prop Element Offsetwidth ❯