# JavaScript Math.max() Explained with Examples

**URL:** <https://forum.freecodecamp.org/t/javascript-math-max-explained-with-examples/14682>\
**Category:** freeCodeCamp Contributors\
**Tags:** guide\
**Created:** [June 26, 2016, 4:50pm UTC](https://forum.freecodecamp.org/t/javascript-math-max-explained-with-examples/14682 "2016-06-26T16:50:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![camperbot](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/camperbot/32/18364_2.png) [@camperbot](https://forum.freecodecamp.org/u/camperbot)\
**Post date:** [June 26, 2016, 4:50pm UTC](https://forum.freecodecamp.org/t/javascript-math-max-explained-with-examples/14682/1 "2016-06-26T16:50:40Z")

</div>

## Math Max

`Math.max()` is a function that returns the largest value from a list of numeric values passed as parameters. If a non-numeric value is passed as a parameter, `Math.max()` will return `NaN` .

An array of numeric values can be passed as a single parameter to `Math.max()` using either `spread (...)` or `apply` . Either of these methods can, however, fail when the amount of array values gets too high.

### Syntax

```auto
Math.max(value1, value2, value3, ...);

```

### Parameters

Numbers, or limited array of numbers.

### Return Value

The greatest of given numeric values, or `NaN` if any given value is non-numeric.

### Examples

_Numbers As Parameters_

```auto
Math.max(4, 13, 27, 0, -5); // returns 27

```

_Invalid Parameter_

```auto
Math.max(4, 13, 27, 'eight', -5); // returns NaN

```

_Array As Parameter, Using Spread(…)_

```auto
let numbers = [4, 13, 27, 0, -5];

Math.max(...numbers); // returns 27

```

_Array As Parameter, Using Apply_

```auto
let numbers = [4, 13, 27, 0, -5];

Math.max.apply(null, numbers); // returns 27

```

---

<div class="post-metadata">

**Author:** ![kevcomedia](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/kevcomedia/32/125737_2.png) [@kevcomedia](https://forum.freecodecamp.org/u/kevcomedia)\
**Post date:** [August 7, 2017, 1:47am UTC](https://forum.freecodecamp.org/t/javascript-math-max-explained-with-examples/14682/2 "2017-08-07T01:47:21Z")

</div>

Closed on August 7, 2017, 1:47am UTC


