JavaScript Math.hypot() Method
The Math.hypot() static method returns the square root of the sum of squares of its arguments, such as the distance between two points.
Description
The Math.hypot() static method returns the square root of the sum of the squares of its arguments. With two arguments, it gives the length of a right triangle's hypotenuse, or the distance between two points: Math.hypot(x2 - x1, y2 - y1). It avoids overflow problems that writing the formula by hand can cause.
With one argument it returns the absolute value, and with no arguments it returns 0. If any argument is Infinity, the result is Infinity, even if another argument is NaN.
Distances between points are common in games, drag-and-drop interactions and canvas drawing, such as checking whether a click is inside a circle: Math.hypot(x - cx, y - cy) <= radius. Like every member of Math, it's called on the Math object itself rather than on a number, and it only works with the Number type: passing a BigInt throws a TypeError.
Syntax
Math.hypot(value1, value2, ...)Parameters
- value1, value2, ...Numbers.
Return Value
The square root of the sum of the squares of the arguments.
Example
Browser Support
The following information will show you the current browser support for the Math.hypot() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





