A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.geeksforgeeks.org/javascript/javascript-math-hypot-method/ below:

JavaScript Math hypot( ) Method

JavaScript Math hypot( ) Method

Last Updated : 15 Jul, 2024

The Math.hypot() method in JavaScript is used to calculate the square root of the sum of squares of numbers passed to it as arguments. 

It is basically used to find the hypotenuse of a right-angled triangle or the magnitude of a complex number. Math.hypot() method uses the formula Math.sqrt(v1*v1 + v2*v2) where v1 and v2 are either the sides of the triangle or the real and complex values. 

The hypot() is a static method of Math and therefore it is always used as Math.hypot() and not as a method of a Math object created. 

Syntax:
Math.hypot(value1, value2,....)
Parameters:

The Math.hypot() method accepts a list of numbers as parameters separated by the comma ',' operator. In the above syntax, value1, and value2 are values that the user wants to send to the hypot() method.

Return Value:

The Math.hypot() method returns the square root of the sum of squares of the passed arguments. It returns NaN if at least one of the arguments cannot be converted to a number. 

Example 1: When two positive numbers are passed as parameters: 

JavaScript
console.log(Math.hypot(3, 4)); 

Example 2: When two negative numbers are passed as parameters: 

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

Example 3: When more than two numbers are passed as parameters: 

JavaScript
console.log(Math.hypot(3, 6, 7));

We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.

Supported Browsers:

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4