Computer >> Computer tutorials >  >> Programming >> Javascript

Math.atan2() function in JavaScript


The atan2() function of the Math object accepts two numbers representing y and x axis and returns the angle between the given point and the positive x-axis in radians. To convert the resultant value into degrees, multiply it with 180 and divide the result by 3.14159 (pi value).

Syntax

Its Syntax is as follows

Math.atan2(10, 5)

Example

<html>
<head>
   <title>JavaScript Example</title>
</head>
<body>
   <script type="text/javascript">
      var result = Math.atan2(10, 5);
      document.write("Hyperbolic arctangent value: "+result);
      document.write("<br>");
      document.write("Hyperbolic arctangent value in degrees: "+result*180/Math.PI);
   </script>
</body>
</html>

Output

Hyperbolic arctangent value: 1.1071487177940904
Hyperbolic arctangent value in degrees: 63.43494882292201