JavaScript ATAN2

The JavaScript ATAN2 function is one of the Math functions, which is used to returns the angle (in radius) from the X-Axiss to the specified point (y, x). The basic syntax of the JavaScript ATAN2 Function is as shown below:

Math.atan2(y, x);

X: represent Cartesian X – Coordinate and Y represent Cartesian Y – Coordinate. If anyone of the argument is Null Value, it will convert the Null value to Zero. If any of the argument is not a number, it will return NaN.

JavaScript ATan2 Function Example

In this ATAN2 example, we find the angle (in radius) with different data types and display the output. Please refer TAN Function in JavaScript to understand the Tangent function

<!DOCTYPE html>
<html>
<head>
    <title> JavaScript ATAN2 Function </title>
</head>
<body>
  <h1> JavaScript ATAN2 Function </h1>
  <p id = "Pos"></p>
  <p id = "Neg"></p>
  <p id = "Dec"></p>
  <p id = "Neg_Dec"></p>
  <p id = "Str"></p>
  <p id = "Str1"></p>
  <p id = "Null"></p>
  <p id = "Multi"></p>
 <script>
    document.getElementById("Pos").innerHTML = Math.atan2(2, 4);
    document.getElementById("Neg").innerHTML = Math.atan2(-1, 6);
    document.getElementById("Dec").innerHTML = Math.atan2(2.45, 0.45);
    document.getElementById("Neg_Dec").innerHTML = Math.atan2(-4.75, -0.75);
    document.getElementById("Str").innerHTML = Math.atan2("5", "11");
    document.getElementById("Str1").innerHTML = Math.atan2("Js", "JavaScript");
    document.getElementById("Null").innerHTML = Math.atan2(null, 4);
    document.getElementById("Multi").innerHTML = Math.atan2(2 + 7 - 4, 9-5);
  </script>
</body>
</html>
JavaScript ATAN2 Function