라이브러리
[JAVASCRIPT] Math.max(a, b, …) - 최댓값 반환
Math.max(a, b, ...) 함수
JavaScript의 Math.max() 함수는 여러 개의 숫자를 비교하여 가장 큰 값을 반환합니다. 이 함수는 하나 이상의 인자를 받을 수 있으며, 인자 중 가장 큰 값을 반환합니다.
사용법
Math.max() 함수는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
javascript
Math.max(a, b, c, d, ...);
예제
# 예제 1: 두 개의 숫자를 비교
#hostingforum.kr
javascript
console.log(Math.max(5, 10)); // 10
# 예제 2: 세 개의 숫자를 비교
#hostingforum.kr
javascript
console.log(Math.max(5, 10, 20)); // 20
# 예제 3: 여러 개의 숫자를 비교
#hostingforum.kr
javascript
console.log(Math.max(5, 10, 20, 30, 40)); // 40
# 예제 4: 음수와 양수를 비교
#hostingforum.kr
javascript
console.log(Math.max(-5, 10)); // 10
# 예제 5: NaN (Not a Number)과 비교
#hostingforum.kr
javascript
console.log(Math.max(NaN, 10)); // NaN
# 예제 6: Infinity와 비교
#hostingforum.kr
javascript
console.log(Math.max(Infinity, 10)); // Infinity
참고
Math.max() 함수는 숫자만 비교할 수 있습니다. 문자열이나 객체는 비교할 수 없습니다. 또한, NaN (Not a Number)과 Infinity는 비교할 수 없습니다.
결론
Math.max() 함수는 여러 개의 숫자를 비교하여 가장 큰 값을 반환하는 유용한 함수입니다. 이 함수를 사용하여 다양한 상황에서 숫자를 비교할 수 있습니다.
-
- 나우호스팅 @pcs8404
-
호스팅포럼 화이팅!
댓글목록
등록된 댓글이 없습니다.