Cute Polka Dotted Red Bow Tie Ribbon

프론트엔드/JavaScript

[JavaScript] Math 객체

jungyoon 2023. 1. 6. 15:36

자바스크립트는 다른 언어와는 달리 쉬운 Math 메소드를 제공하고 있다.

가장 많이 쓰이는 Math 메소드는 다음과 같다.

  1. Math.pow()
  2. Math.min()
  3. Math.max()
  4. Math.round()
  5. Math.floor()
  6. Math.ceil()
  7. Math.sqrt()
  8. Math.random()

Math.pow()
Math.pow(5,2);
->25

Math.min()
Math.min(1,2,3,4,5);
->1

Math.max()
Math.max(1,2,3,4,5);
->5

Math.round()
Math.round(10.7);
->11

Math.floor()
Math.floor(10.6);
->10

Math.ceil()
Math.ceil(10.1);
->11

Math.sqrt()
Math.sqrt(9);
->3

Math.random()
Math.random();
->0부터 1.0 사이의 랜덤한 숫자

 

'프론트엔드 > JavaScript' 카테고리의 다른 글

[JS] JSON.parse()와 JSON.stringify() 사용법  (0) 2024.08.13