It is basically used to find the hypotenuse of a right-angled triangle or the magnitude of a complex number. Math.hypot() function uses the formula Math.sqrt(v1*v1 + v2*v2) where v1 and v2 are either the sides of the triangle or the real and complex values.
The hypot() is a static method of Math and therefore it is always used as Math.hypot() and not as a method of a Math object created.
Parameters: The Math.hypot() function accepts a list of numbers as parameters separated by the comma ‘,’ operator. In the above syntax, value1, and value2 are values that the user wants to send to the hypot() function.
Return Value: The Math.hypot() function returns the square root of the sum of squares of the passed arguments. It returns NaN if at least one of the arguments cannot be converted to a number.
Example 1: When two positive numbers are passed as parameters:
Example 2: When two negative numbers are passed as parameters:
Example 3: When more than two numbers are passed as parameters:
- Google Chrome 38 and above
- Firefox 27 and above
- Opera 25 and above
- Safari 8 and above