JavaScript Math hypot() method - JavaScript Tutorial

JavaScript Math hypot() method

BLUF: This tutorial on JavaScript Math hypot() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Math hypot() method

Understanding JavaScript Math hypot() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

The hypot method in JavaScript calculates the square root of the total of the squares of the provided numbers. If any of the arguments cannot be transformed into a numerical value, it will return NaN.

Syntax

The syntax for the hypot function is outlined as follows:

Example

Math.hypot([num1[, num2[, ...]]])

Parameter

Num - A number.

Return

The square root of the total obtained from the squares of the provided numbers.

JavaScript Math hypot method example

In this section, we will explore the hypot function by examining several examples.

Example 1

Let's see a simple example of hypot method.

Example

<script>

document.writeln(Math.hypot(3,4)+"<br>");

document.writeln(Math.hypot(12,5));

</script>

Output:

Example 2

Let’s examine an instance of the hypot function utilizing three parameters.

Example

<script>

document.writeln(Math.hypot(2,3,4)+"<br>");

document.writeln(Math.hypot(-2,-5,-8));

</script>

Output:

Output

5.385164807134504

9.643650760992955

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience