JavaScript Math.SQRT1_2 Property
In mathematics, a positive number, when multiplied by itself, represents the square of the number. For instance, 5 is the square root of 25, then it is represented as 5=25 or we can show the same equation as 5^2 = 25.
The JavaScript Math.SQRT1_2 property is a predefined constant in the Math object which represents the square root of 1/2. This property is equivalent to Math.sqrt(0.5). It is one of the many properties provided by the Math object to perform mathematical operations in JavaScript.
Syntax
Following is the syntax of JavaScript Math.SQRT1_2 property −
Math.SQRT1_2
Return value
This propety returns the square root of 1/2.
Example 1
In the following example, we are using the JavaScript Math.SQRT1_2 property to return the square root of 1/2 −
<html> <body> <script> const result = Math.SQRT1_2; document.write(result); </script> </body> </html>
Output
If we execute the above program, this property returns approximately "0.70710".
Example 2
Here, we are calculating the square root of 1/2 and comparing it with Math.SQRT1_2 property −
<html> <body> <script> const value = Math.sqrt(1 / 2); document.write(value === Math.SQRT1_2); </script> </body> </html>
Output
After executing the above program, it returns "true" as result because both are equal.
Example 3
Here, the function calPerOfRootHalf uses Math.SQRT1_2 to calculate 70.7% of the given value (10) −
<html>
<body>
<script>
function calPerOfRootHalf(value) {
return value * Math.SQRT1_2;
}
const result = calPerOfRootHalf(10);
document.write(result);
</script>
</body>
</html>
Output
If we execute the program , it returns "7.07106" as result.