Math.hypot()

Returns the square root of the sum of squares of its arguments (Euclidean norm).

Since ES2015 Spec ↗

Syntax

Math.hypot(...values)

Parameters

NameTypeRequiredDescription
values number No Zero or more numbers.

Returns

number — sqrt(v1^2 + v2^2 + ...); 0 if no arguments.

Examples

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

Notes

Computes distance/magnitude while avoiding intermediate overflow or underflow that `Math.sqrt(a*a + b*b)` can suffer. Accepts any number of dimensions.

Browser & runtime support

EnvironmentSince version
chrome 38
firefox 27
safari 8
edge 12
node 0.12

See also