How to use the Math.hypot() function to get the square root of the sum of squares of its arguments in JavaScript

1 Answer

0 votes
document.write("Math.hypot(3, 4) = " + Math.hypot(3, 4) + "<br />");
document.write("Math.hypot(3, 4) = Math.sqrt(3*3 + 4*4) = " + Math.sqrt(3*3 + 4*4) + "<br />");
document.write("Math.hypot(1, 1) = " + Math.hypot(1, 1) + "<br />");
document.write("Math.hypot() = " + Math.hypot() + "<br />");
document.write("Math.hypot(3, 4, 5) = " + Math.hypot(3, 4, 5) + "<br />");
document.write("Math.hypot(NaN) = " + Math.hypot(NaN) + "<br />");
document.write("Math.hypot(-9) = " + Math.hypot(-9) + "<br />");
document.write("Math.hypot(3, 4, 7) = " + Math.hypot(3, 4, 7) + "<br />");
document.write("Math.hypot(3, 4, '7') = " + Math.hypot(3, 4, '7') + "<br />");


 
/*
run

Math.hypot(3, 4) = 5
Math.hypot(3, 4) = Math.sqrt(3 * 3 + 4 * 4) = 5
Math.hypot(1, 1) = 1.4142135623730951
Math.hypot() = 0
Math.hypot(3, 4, 5) = 7.0710678118654755
Math.hypot(NaN) = NaN
Math.hypot(-9) = 9
Math.hypot(3, 4, 7) = 8.602325267042627
Math.hypot(3, 4, '7') = 8.602325267042627
 
*/

 



answered Aug 2, 2016 by avibootz
...