[JAVA SCRIPT] 정수의 제곱근과 거듭제곱

차슈·2024년 4월 29일
0

JAVA SCRIPT

목록 보기
20/24
post-thumbnail

제곱근

제곱근을 구하는 함수는 Math.sqrt()

Math.sqrt(x);
Math.sqrt(대상 숫자);

Math.sqrt(121) // 11

Math.sqrt(9); // 3
Math.sqrt(2); // 1.414213562373095

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

음수이면 NaN 반환
Maht.sqrt()


거듭제곱

Math.pow()

Math.pow(대상숫자, 거듭제곱 횟수);

Math.pow(3,2) // 9


console.log(Math.pow(7, 3));
// Expected output: 343

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

console.log(Math.pow(7, -2));
// Expected output: 0.02040816326530612
//                  (1/49)

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

정수 판별하기

Number.isInteger()

Number.isInteger(value)
value가 정수이면 ture, 정수가 아닐때 false 반환

Number.isInteger(1)// true 
Number.isInteger(-144) //false
Number.isInteger(true); // false
Number.isInteger(false); // false
Number.isInteger([1]); // false
Number.isInteger(5.0); // true

0개의 댓글