728x90

✨ 절대값을 이용한 계산이 필요할 때 사용할 수 있는 helper method

💻Example Code

const x1 = 5;
const x2 = 3;

console.log(x2-x1);
console.log(x1-x2);
console.log(Math.abs(x2-x1));
console.log(Math.abs(x1-x2));

🧨 두 점 사이의 거리 등 다양한 계산에서 활용할 수 있다.

👉 자세한 내용은 https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Math/abs

 

Math.abs()

Math.abs() 함수는 주어진 숫자의 절대값을 반환합니다.

developer.mozilla.org

 

'JavaScript > Built-in Method etc.' 카테고리의 다른 글

String.prototype.localeCompare()  (0) 2020.02.20
Math.round()  (0) 2020.02.16
Math.PI  (0) 2020.01.28
Array.prototype.forEach()  (0) 2020.01.23
Math.pow()  (0) 2020.01.22

+ Recent posts