[inflearn] javascript: math

eve·2023년 2월 8일
0

frontend

목록 보기
29/40

1. Math.PI

console.log(Math.PI); // -> 3.14156 ...

파이값을 반환한다.




2. Math.round()

console.log(Math.round(4.7)); // -> 5

반올림 해주는 함수이다.




3. Math.pow()

console.log(Math.pow(2, 8)); // -> 256

첫번째 인자를 두번째 인자만큼 제곱하게 하는 함수이다.




4. Math.sqrt()

console.log(Math.sqrt(64)); // -> 8

제곱근을 구해주는 함수이다.




5. Math.abs()

console.log(Math.abs(-5)); // -> 5

절댓값을 구하는 함수이다.




5. Math.random()

console.log(Math.random()); // -> 0.?????

소수점 아래 난수를 생성한다.
Math.random()*10를 할 경우에는 1부터 10의 수를 생성.




6. Math.max(), .min()

console.log(Math.max(1, 2, 3)); // -> 3
console.log(Math.min(1, 2, 3)); // -> 1

최댓값과 최솟값을 반환한다.

profile
유저가 왜 그랬을까

0개의 댓글