Math.hypot(...values) returns the square root of the sum of the squares of its arguments. With two values, it gives the length of the longest side (hypotenuse) of a right triangle.
Math is built into JavaScript. Call the method directly. It is not a constructor, so never write new Math().
Syntax
Call Math.hypot() like this. Start with this line.
JavaScript
Math.hypot(value1, value2, /* …, */ valueN)
Call
What it does
Math.hypot(value1, value2, ...)
Returns the square root of the sum of the squares of all values.
Math.hypot()
With no arguments, returns 0.
Built into JavaScript. Call Math.hypot() on the Math object — no import required.
Library declarations
JavaScript
Math.hypot(value1, value2, /* …, */ valueN)
JavaScript
interface Math {
hypot(...values: number[]): number;
}
Parameters
Parameter
Description
value1, ..., valueN
Optional. Any number of numbers. With no values, the result is 0.
Return Value
Return Value
Description
number
The square root of the sum of squares. Returns Infinity if any value is Infinity, and NaN if any value is NaN (and none is Infinity).
JavaScript Examples
Example 1 — Basic Use
Pass the sides of a right triangle. You get the longest side.