Math.hypot()
Returns the square root of the sum of squares of its arguments (Euclidean norm).
Syntax
Math.hypot(...values) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
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
| Environment | Since version |
|---|---|
| chrome | 38 |
| firefox | 27 |
| safari | 8 |
| edge | 12 |
| node | 0.12 |