Get to know MDN better
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The Math.atan2() static method returns the angle in the plane (in radians) between the positive x-axis and the ray from (0, 0) to the point (x, y), for Math.atan2(y, x).
The y coordinate of the point.
xThe x coordinate of the point.
The angle in radians (between -π and π, inclusive) between the positive x-axis and the ray from (0, 0) to the point (x, y).
The Math.atan2() method measures the counterclockwise angle θ, in radians, between the positive x-axis and the point (x, y). Note that the arguments to this function pass the y-coordinate first and the x-coordinate second.
Math.atan2() is passed separate x and y arguments, while Math.atan() is passed the ratio of those two arguments. Math.atan2(y, x) differs from Math.atan(y / x) in the following cases:
| Infinity | Infinity | π / 4 | NaN |
| Infinity | -Infinity | -π / 4 | NaN |
| -Infinity | Infinity | 3π / 4 | NaN |
| -Infinity | -Infinity | -3π / 4 | NaN |
| 0 | 0 | 0 | NaN |
| 0 | -0 | -0 | NaN |
| < 0 (including -0) | 0 | π | 0 |
| < 0 (including -0) | -0 | -π | 0 |
| -Infinity | > 0 | π | -0 |
| -0 | > 0 | π / 2 | -π / 2 |
| -Infinity | < 0 | -π | 0 |
| -0 | < 0 | -π / 2 | π / 2 |
In addition, for points in the second and third quadrants (x < 0), Math.atan2() would output an angle less than -π2-\frac{\pi}{2} or greater than π2\frac{\pi}{2}.
Because atan2() is a static method of Math, you always use it as Math.atan2(), rather than as a method of a Math object you created (Math is not a constructor).
The following script prints all inputs that produce a difference between Math.atan2(y, x) and Math.atan(y / x).
The output is:
| x | y | atan2 | atan | |-------|-------|-------|-------| | -∞ | -∞ | -3π/4 | NaN | | -∞ | -1 | -π | 0 | | -∞ | -0 | -π | 0 | | -∞ | 0 | π | -0 | | -∞ | 1 | π | -0 | | -∞ | ∞ | 3π/4 | NaN | | -1 | -∞ | -π/2 | π/2 | | -1 | -1 | -3π/4 | π/4 | | -1 | -0 | -π | 0 | | -1 | 0 | π | -0 | | -1 | 1 | 3π/4 | -π/4 | | -1 | ∞ | π/2 | -π/2 | | -0 | -∞ | -π/2 | π/2 | | -0 | -1 | -π/2 | π/2 | | -0 | -0 | -π | NaN | | -0 | 0 | π | NaN | | -0 | 1 | π/2 | -π/2 | | -0 | ∞ | π/2 | -π/2 | | 0 | -0 | -0 | NaN | | 0 | 0 | 0 | NaN | | ∞ | -∞ | -π/4 | NaN | | ∞ | ∞ | π/4 | NaN || ECMAScript® 2027 Language Specification # sec-math.atan2 |
Enable JavaScript to view this browser compatibility table.
This page was last modified on Dec 29, 2025 by MDN contributors.
Your blueprint for a better internet.
Visit Mozilla Corporation’s not-for-profit parent, the Mozilla Foundation.
Portions of this content are ©1998–2026 by individual mozilla.org contributors. Content available under a Creative Commons license.