The hypot method in JavaScript calculates the square root of the total of the squares of the provided numbers. If any of the arguments cannot be transformed into a numerical value, it will return NaN.
Syntax
The syntax for the hypot function is outlined as follows:
Example
Math.hypot([num1[, num2[, ...]]])
Parameter
Num - A number.
Return
The square root of the total obtained from the squares of the provided numbers.
JavaScript Math hypot method example
In this section, we will explore the hypot function by examining several examples.
Example 1
Let's see a simple example of hypot method.
Example
<script>
document.writeln(Math.hypot(3,4)+"<br>");
document.writeln(Math.hypot(12,5));
</script>
Output:
Example 2
Let’s examine an instance of the hypot function utilizing three parameters.
Example
<script>
document.writeln(Math.hypot(2,3,4)+"<br>");
document.writeln(Math.hypot(-2,-5,-8));
</script>
Output:
Output
5.385164807134504
9.643650760992955