Explica este código JavaScript
Dificultad: Básico
console.log(Math.hypot(3, 4))
- A.
25
- B.
5
- C.
hypot is not a function
- D.
Ninguna de las anteriores
Lo que hace es elevar al cuadrado ambos parámetros, sumarlos y luego sacarle su raíz cuadrada. Podríamos llegar a lo mismo usando otros métodos:Respuesta:
5
Math.hypot
es una manera de resolver el Teorema de Pitágoras en JavaScript.
const pitagoras = (a, b) => {
return Math.sqrt(a ** 2 + b ** 2)
}
console.log(pitagoras(3,4)) // 5