Math.sqrt()

 Math.sqrt() 함수는 숫자의 제곱근을 반환합니다.

x0,Math.sqrt(x)=x=the uniquey0such thaty2=x\forall x \geq 0, \mathtt{Math.sqrt(x)} = \sqrt{x} = \text{the unique} \; y \geq 0 \; \text{such that} \; y^2 = x

문법

Math.sqrt(x)

매개변수

x
숫자.

반환 값

주어진 숫자에 루트(√ )를 씌웁니다. 만약 숫자가 음수이면 NaN를 반환합니다.

설명

만약 x 가 음수라면 Math.sqrt() 함수는 NaN를 반환합니다.

sqrt()는 Math의 정적 메서드 이므로 만든  Math 객체의 메서드가 아니라 항상 Math.sqrt()함수를 사용해야합니다. (Math는 생성자가 없습니다.)

예제

 Math.sqrt()

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

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

표준

표준 상태 비고
ECMAScript 1st Edition (ECMA-262) Standard Initial definition. Implemented in JavaScript 1.0.
ECMAScript 5.1 (ECMA-262)
The definition of 'Math.sqrt' in that specification.
Standard  
ECMAScript 2015 (6th Edition, ECMA-262)
The definition of 'Math.sqrt' in that specification.
Standard  
ECMAScript Latest Draft (ECMA-262)
The definition of 'Math.sqrt' in that specification.
Draft  

브라우저 호환성

Update compatibility data on GitHub
DesktopMobileServer
ChromeEdgeFirefoxInternet ExplorerOperaSafariAndroid webviewChrome for AndroidFirefox for AndroidOpera for AndroidSafari on iOSSamsung InternetNode.js
sqrtChrome Full support 1Edge Full support 12Firefox Full support 1IE Full support 3Opera Full support YesSafari Full support YesWebView Android Full support 1Chrome Android Full support 18Firefox Android Full support 4Opera Android Full support YesSafari iOS Full support YesSamsung Internet Android Full support 1.0nodejs Full support Yes

Legend

Full support  
Full support

참조