What is Math.hypot() in JavaScript?

Math is a built-in object in JavaScript that contains different methods and properties used to perform mathematical operations. It contains a hypot() function, which is used to compute the magnitude of a specified number. It is short for hypotenuse.

hypot()=x02+x12+...+xn2hypot() = \sqrt{{x_0^2}+{x_1^2}+{...} +{x_n^2}}

Syntax

Math.hypot(param1, param2, ...paramN);

Parameter

  • param1, param2, ... paramN: These are the input parameters, which can be of any number ranging from 0 to N. They are of the Number type.

Number in JavaScript is a 64-bit double-precision value that is the same as double in C# or Java.

Return value

  • Number: It returns the square root of the sum of squares of its arguments. It is of the Number type.

  • NaN: The function returns this if any of the input parameters are not a Number.

Code

console.log("hypot() = " + Math.hypot());
console.log("hypot(-2) = " + Math.hypot(-2));
console.log("hypot(2,3,'4') = " + Math.hypot(2,3,'4'));
console.log("hypot(NaN) = " + Math.hypot(NaN));
console.log("hypot(2,3,'educative') = " + Math.hypot(2,3,'educative'));
console.log("hypot(2,3,4) = " + Math.hypot(2,3,4));

Free Resources