JS_10_ Math( )_내장객체

hyeong taek jo·2023년 8월 14일
0

Java Script

목록 보기
10/22
  • math객체는 수학에서 자주 사용하는 상수와 함수들을 미리 구현해 놓은 자바스크립트 표준 내장 객체
  • math객체는 다른 전역 객체와는 달리 생성자(constructor)가 존재하지 않음 따로 인스턴스를 생성하지 않아도 Math 객체의 모든 메소드나 프로퍼티를 바로 사용할 수 있음
<script type="text/javascript">
	// min
	console.log(Math.min(1, 10, -100, -10, 1000, 0));
	console.log(Math.min()); // Infinity 인수전달 안 될시
	
	// 인수 중에 비교할 수 없는 값이 포함되어 있으면 NaN
	console.log(Math.min(1, 10, -100, -10, "문자열", 0));
	
	// max
	console.log(Math.max(1, 10, -100, -10, 1000, 0));

	console.log("-------------round------------------");
	
	//round
	console.log(Math.round(10.43)); //
	console.log(Math.round(10.78)); //
	console.log(Math.round(-10.52)); //
	console.log("-------------floor------------------");
	
	//floor
	console.log(Math.floor(10.43)); //
	console.log(Math.floor(10.78)); //
	console.log(Math.floor(-10.52)); //
	console.log("-------------ceil------------------");
	
	//ceil
	console.log(Math.ceil(10.43)); //
	console.log(Math.ceil(10.78)); //
	console.log(Math.ceil(-10.52)); //
</script>

profile
마포구 주민

0개의 댓글