Math.atan2()

Returns the angle in radians between the positive x-axis and the point (x, y).

Since ES1 Spec ↗

Syntax

Math.atan2(y, x)

Parameters

NameTypeRequiredDescription
y number Yes The y coordinate of the point.
x number Yes The x coordinate of the point.

Returns

number — The angle in radians, between -PI and PI.

Examples

console.log(Math.atan2(1, 1));
Output
0.7853981633974483
console.log(Math.atan2(1, 0) === Math.PI / 2);
Output
true

Notes

Note the argument order is (y, x), not (x, y). Unlike `Math.atan`, it uses the signs of both arguments to return the correct quadrant. Convert to degrees with `result * 180 / Math.PI`.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also