Home >>JavaScript Math Reference >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 | 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. |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
atan2() | Yes | Yes | Yes | Yes | Yes |
<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>
Click the button to see the Output.
<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>
Click the button to see the Output.