要获得平方根,请使用Math.sqrt()方法。此方法返回数字的平方根。如果数字的值为负,则sqrt返回NaN。
您可以尝试运行以下代码来获取数字的平方根-
<html>
<head>
<title>JavaScript Math sqrt() Method</title>
</head>
<body>
<script>
var value = Math.sqrt( 0.5 );
document.write("First Value : " + value );
var value = Math.sqrt( 49 );
document.write("<br />Second Value : " + value );
</script>
</body>
</html>