[JavaScript] Number.isInteger() & 제곱근 (pow, sqrt)

해버니·2022년 10월 21일
0

JavaScript

목록 보기
3/5
post-thumbnail

Number.isInteger()

특정 값이 정수인지 판별해주는 메서드
Number.isInteger(value)


Number.isInteger(3000);		// true
Number.isInteger(-3000);	// true
Number.isInteger(3000.333);	// false
Number.isInteger(NaN);		// false	
Number.isInteger(Infinity);	// false






제곱근

Math.pow()

pow는 특정 숫자의 거듭제곱 값을 계산해주는 함수이다.
pow = power = 제곱


Math.pow([대상 숫자], [거듭제곱 횟수]);
Math.pow(base, exponent);
  • base : The baser number.
  • exponent : The exponent used to raise the base.




Math.pow(3, 1);		// 3
Math.pow(3, 2);		// 9
Math.pow(3, 3);		// 27

Math.pow(-3, 1);	// -3
Math.pow(-3, 2);	// 9
Math.pow(-3, 3);	// -27

Math.pow(3, -1);	// 0.3333333333333333
Math.pow(3, -2);	// 0.1111111111111111
Math.pow(3, -3);	// 0.037037037037037035

Math.pow(-3, -1);	// -0.3333333333333333
Math.pow(-3, -2);	// 0.1111111111111111
Math.pow(-3, -3);	// -0.037037037037037035

Math.pow(3, 0.5);	// 1.7320508075688772
Math.pow(-3, 0.5);	// NaN




Math.sqrt()

sqrt는 특정 숫자의 제곱근 값을 계산해주는 함수이다.
sqrt = Squre root = 제곱근

만약 매개변수가 음수이면 NaN을 반환한다.

Math.sqrt(121);	// 11
Math.sqrt(20);	// 4.47213595499958
Math.sqrt(-1);	// NaN




0개의 댓글