Die JavaScript-Funktion Math.hypot () gibt die Quadratwurzel der Quadratsumme ihrer Argumente zurück.
Es kehrt zurück Math.sqrt(n1*n1 + n2*n2 +… + nx*nx)
.
Es repräsentiert den Abstand zwischen Punkten (n1, n2,…, nx) und Ursprung.
Die Syntax der Math.hypot()
Funktion lautet:
Math.hypot(n1, n2,… , nx)
hypot()
Da es sich um eine statische Methode handelt, wird sie mit dem Math
Klassennamen aufgerufen .
Math.hypot () Parameter
Die Math.hypot()
Funktion verwendet beliebige (eine oder mehrere) Zahlen als Argumente.
Rückgabewert von Math.hypot ()
- Gibt die Quadratwurzel der Quadratsumme der angegebenen Argumente zurück.
- Gibt zurück,
NaN
wenn ein Argument nicht numerisch ist. - Gibt +0 zurück, wenn keine Argumente angegeben werden.
Beispiel: Verwenden von Math.hypot ()
var num = Math.hypot(3, 4); console.log(num); // 5 var num = Math.hypot(7, 24, 25); console.log(num); // 35.35533905932738 // single argument is equivalent to absolute value var num = Math.hypot(-3); console.log(num); // 3 var num = Math.hypot(3, 4, "5"); console.log(num); // 7.0710678118654755 // returns +0 for no argument var num = Math.hypot(); console.log(num); // 0
Ausgabe
5 35.35533905932738 3 7.0710678118654755 0
Empfohlene Lektüre:
- JavaScript Math abs ()
- JavaScript Math sqrt ()
- JavaScript Math pow ()