basic

Math.hypot

Returns the square root of the sum of squares of its arguments — the Euclidean norm. Introduced in ES2015 and safer than manual sqrt(a*a + b*b) against overflow.

Math.hypot(...values)

Parameters & edge cases

Case Behavior
...values Any number of numeric arguments (0 or more)
no args Math.hypot() returns 0
overflow-safe Handles very large/small values without intermediate overflow to Infinity

Examples

console.log(Math.hypot(3, 4));      // 5

Classic 3-4-5 Pythagorean triangle.

console.log(Math.hypot(3, 4, 12));  // 13

Works in n dimensions — here, 3D distance from origin.

console.log(Math.hypot());          // 0

Zero arguments give 0 (an empty vector's norm).

console.log(Math.hypot(-3, 4));     // 5

Signs don't matter — squares eliminate them.

Gotcha

In hot loops, Math.hypot is measurably slower than manual `Math.sqrt(a*a + b*b)` because it inspects for overflow — use the manual form only when you know values stay in a safe range.

Related

← All JS Math methods · Array methods