Math.sqrt()
함수는 숫자의 제곱근을 반환합니다.
문법
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 |
브라우저 호환성
The compatibility table in this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
Update compatibility data on GitHub
Desktop | Mobile | Server | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sqrt | Chrome Full support 1 | Edge Full support 12 | Firefox Full support 1 | IE Full support 3 | Opera Full support Yes | Safari Full support Yes | WebView Android Full support 1 | Chrome Android Full support 18 | Firefox Android Full support 4 | Opera Android Full support Yes | Safari iOS Full support Yes | Samsung Internet Android Full support 1.0 | nodejs Full support Yes |
Legend
- Full support
- Full support