Favorites

JavaScript Math.hypot() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Math.hypot()
JavaScript Math Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

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

console.log(Math.hypot(3, 4));
const a = { x: 1, y: 1 }, b = { x: 4, y: 5 };
console.log(Math.hypot(b.x - a.x, b.y - a.y));
console.log(Math.hypot(1, 2, 2));

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee