The JavaScript atan2 function is one of the Math functions used to return the angle (in radians) from the X-Axis to the specified point (y, x).
The basic syntax of the atan2 Function is as shown below:
Math.atan2(y, x);
Parameters: X represents the Cartesian X – Coordinate, and Y represents the Cartesian Y – Coordinate. If any of the arguments are null values, it will convert the Null value to zero. If any argument is not a number, it will return NaN.
Return Value: The atan2() function returns radians between -π and π.
JavaScript atan2 Function Example
In this atan2 example, we will find the angle (in radians) using different data types and display the output. Please refer to the tan(), atan(), atan2(), tanh(), and atanh() functions from math methods for finding the arc and hyperbolic tangent values in JavaScript.
<!DOCTYPE html>
<html>
<head>
<title> JavaScriptATAN2Function </title>
</head>
<body>
<h1> JavaScriptATAN2Function </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>

Example 2: Here, we use the atan2() function on zeros and how to handle negative zeros.
console.log(Math.atan2(0, 0));
console.log(Math.atan2(0, -0));
console.log(Math.atan2(-0, 0));
0
3.141592653589793
-0