JavaScript - Math.hypot() Method
The JavaScript Math.hypot() method returns square root of sum of squares of two arguments, i.e., sqrt(x2 +y2).
Syntax
Math.hypot(x, y)
Parameters
x |
Specify a value. |
y |
Specify a value. |
Return Value
Returns sqrt(x2 +y2).
Example:
In the example below, Math.hypot() method is used to calculate sqrt(x2 +y2).
var txt; txt = "Math.hypot(3, 4) = " + Math.hypot(3, 4) + "<br>"; txt = txt + "Math.hypot(5, 12) = " + Math.hypot(5, 12) + "<br>"; txt = txt + "Math.hypot(8, 15) = " + Math.hypot(8, 15) + "<br>"; txt = txt + "Math.hypot(20, 15) = " + Math.hypot(20, 15) + "<br>";
The output (value of txt) after running above script will be:
Math.hypot(3, 4) = 5 Math.hypot(5, 12) = 13 Math.hypot(8, 15) = 17 Math.hypot(20, 15) = 25
❮ JavaScript - Math Object