Math.hypot
Returns the square root of the sum of squares of its arguments
Syntax
Math.hypot(...values)Parameters
| Parameter | Type | Description |
|---|---|---|
| values | number[] | Numbers to compute the hypotenuse for |
Return Value
The square root of the sum of squares of the arguments
Examples
console.log(Math.hypot(3, 4)); // 5
console.log(Math.hypot(5, 12)); // 13function distance3D(x: number, y: number, z: number) {
return Math.hypot(x, y, z);
}
console.log(distance3D(1, 2, 2)); // 3const magnitude = Math.hypot(3, 4, 0);
console.log(magnitude); // 5Understanding Math.hypot
The Math.hypot method in JavaScript returns the square root of the sum of squares of its arguments. It belongs to the Math object and is one of the most widely used methods for working with math values in modern JavaScript and TypeScript applications.
The method signature is Math.hypot(...values). It accepts 1 parameter: values. When called, it returns the square root of the sum of squares of the arguments. Understanding when and how to use hypot() helps you write more expressive, readable code.
Common use cases for Math.hypot include data transformation, input validation, API response processing, and building reusable utility functions. It works well alongside related methods like math-sqrt, math-pow, enabling you to chain operations together for complex data manipulation pipelines.
Browser support for Math.hypot is excellent across all modern browsers including Chrome, Firefox, Safari, and Edge. It is also fully supported in Node.js and Deno. For older environments, transpilation with Babel or a polyfill may be needed.
Browser Compatibility
Supported in all modern browsers (Chrome, Firefox, Safari, Edge) and Node.js. Part of the ECMAScript standard.
Related Methods
More Math Methods
Other methods in the Math object
Related Tools
More Math Methods
Explore JavaScript Methods
Browse our complete reference of 410 JavaScript methods with syntax, examples, and explanations.