Get to know MDN better
This page was translated from English by the community. Learn more and join the MDN Web Docs community.
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015년 7월.
Math.max() 정적 메서드는 매개변수로 주어진 숫자 중 가장 큰 수를 반환하거나, 매개변수가 없을 경우 -Infinity를 반환합니다.
가장 큰 값을 선택하고 반환할 0개 이상의 숫자입니다.
주어진 숫자 중 가장 큰 숫자를 반환합니다. 만약 인수 중 하나라도 숫자로 변환한 값이 NaN이라면 NaN로 반환합니다. 매개변수가 없을 경우 -Infinity를 반환합니다.
max()는 Math의 정적 메서드이기 때문에 만든 Math객체의 메서드가 아닌 항상 Math.max()로 사용해야합니다. (Math는 생성자가 아닙니다).
Math.max.length의 값이 2 인데, 이는 이 메서드가 최소 2개의 매개변수를 받도록 설계되었음을 암시합니다.
Array.prototype.reduce()는 각 값을 비교하여 숫자 배열의 최대 요소를 찾는 데 사용할 수 있습니다.
다음 함수는 Function.prototype.apply()를 사용하여 배열의 최대값을 가져옵니다. getMaxOfArray([1, 2, 3])는 Math.max(1, 2, 3)와 동일하지만, 프로그래밍 방식으로 배열을 생성하기 위해 getMaxOfArray()를 사용할 수 있습니다. 이 함수는 상대적으로 요소가 적은 배열에만 사용해야 합니다.
전개 구문은 배열의 최대값을 구하기 위한 apply 솔루션을 짧게 작성하는 방법입니다.
그러나 전개 구문(...)와 apply는 모두 배열 요소를 함수 매개변수로 전달하려고 하기 때문에 배열에 요소가 너무 많으면 실패하거나 잘못된 결과를 반환합니다. 자세한 내용은 apply와 내장 함수 사용하기를 참조하세요. reduce 솔루션에는 이 문제가 없습니다.
| ECMAScript® 2027 Language Specification # sec-math.max |
Enable JavaScript to view this browser compatibility table.
This page was last modified on 2025년 2월 11일 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.