Home >>JavaScript Math Reference >JavaScript atan2() Method

JavaScript atan2() Method

JavaScript atan2() Method

JavaScript atan2() method is used to return the arctangent value of the quotient of the given input arguments. It returns a numeric value between PI and -PI radian as the output. In this the y coordinate is passed as the first argument and the x coordinate is passed as the second argument.

Syntax:
Math.atan2(y, x)

Parameter Values

Parameter Description
y This is a required parameter. It defines the number representing the y coordinate.
x This is a required parameter. It defines the number representing the x coordinate.

Browser Support

Method Chrome Edge Firefox Safari Opera
atan2() Yes Yes Yes Yes Yes
Here is an example of JavaScript atan2() method:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction()">Try it</button>
<p id="demo"></p>
<script>
function myFunction() {
  document.getElementById("demo").innerHTML = Math.atan2(6, 3);
}
</script>
</body>
</html>
Output:

Click the button to see the Output.

Example 2:
<html>
<body>
<p>Click the button to see the Output.</p>
<button onclick="myFunction1()">Try it</button>
<p id="demo1"></p>
<script>
function myFunction1() {
  document.getElementById("demo1").innerHTML = Math.atan2(4, 3);
}
</script>
</body>
</html>
Output:

Click the button to see the Output.


No Sidebar ads