JavaScript Math.SQRT2 Property
The Math.SQRT2 property in JavaScript represents the square root of 2, that is approximately 1.41421. It is a predefined property of the Math object in JavaScript. This property is equivalent to Math.sqrt(2).
Syntax
Following is the syntax of JavaScript Math.SQRT2 property −
Math.SQRT2
Return value
This property returns the square root of 2.
Example 1
In the example below, we are using the JavaScript Math.SQRT2 property to retrieve square root of 2 −
<html> <body> <script> const sqrt2 = Math.SQRT2; document.write(sqrt2); </script> </body> </html>
Output
If we execute the above program, this property returns approximately "1.41421".
Example 2
Here, we are calculating the square root of 2 and comparing it with Math.SQRT2 property −
<html> <body> <script> const value = Math.sqrt(2); document.write(value === Math.SQRT2); </script> </body> </html>
Output
After executing the above program, it returns "true" as result because both the values are equal.
Example 3
In this program, the Math.sqrt(number) calculates the square root of 8, and multiplies it by Math.SQRT2 −
<html> <body> <script> const number = 8; const sqrtOfNumber = Math.sqrt(number) * Math.SQRT2; document.write(sqrtOfNumber); </script> </body> </html>
Output
After executing the program, it returns "4" as result.