프론트엔드 센트럴파크 (☞゚ヮ゚)☞

거듭제곱 / 제곱근 본문

Javascript

거듭제곱 / 제곱근

자라나라나무나무나 2022. 7. 20. 16:55

거듭제곱

Math.pow(base, exponent);
console.log(Math.pow(2, 3));
// output: 8

console.log(Math.pow(4, 0.5));
// output: 2

console.log(Math.pow(6, -2));
// output: 0.027777777777777776
//                  (1/36)

console.log(Math.pow(-7, 0.5));
// output: NaN

 

참고 : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Math/pow

 

제곱근

Math.sqrt(x)
숫자가 음수이면 NaN을 반환한다.
Math.sqrt(9); // 3
Math.sqrt(2); // 1.414213562373095
Math.sqrt(49); // 7

Math.sqrt(1);  // 1
Math.sqrt(0);  // 0
Math.sqrt(-1); // NaN

참고 : https://developer.mozilla.org/ko/docs/Web/JavaScript/Reference/Global_Objects/Math/sqrt

 

Comments