수학(Math) 객체란?
- 수학적인 처리하기 위한 속성과 메서드를 가진 내장 객체
- Number 타입만 지원
Math.ceil(arg) : Number
Math.ceil(0.95); // 1
Math.ceil(4); // 4
Math.ceil(7.004); // 8
Math.ceil(-0.95); // -0
Math.ceil(-4); // -4
Math.ceil(-7.004); // -7
Math.round(arg) : Number
Math.round(0.9); // 1
Math.round(0.6); // 1
Math.round(0.4); // 0
Math.floor(arg) : Number
Math.floor(5.95); // 5
Math.floor(5.05); // 5
Math.floor(5); // 5
Math.random() : Number
- 0이상 1미만의 랜덤한 수를 반환
- 암호학적으로 안전하지 않으므로 보안과 관련된 용도로 사용은 금물
Math.ceil((Math.random() * 10)); // 1 ~ 10까지의 난수를 획득
Math.max(args) : Number
Math.max(1, 2, 3); // 3
let arr = [1, 2, 3, 4];
Math.max(...arr); // 4
Math.min(args): Number