JavaScript (ES2026) reference · Math Methods and Constants

JavaScript Math.atan2() Method

Return the angle in radians between the positive x axis and the point (x, y). Note the argument order: y first.

JavaScript (ES2026) Since ES1

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

Math.atan2(y, x)

Parameters

ParameterDescription
y The y coordinate.
x The x coordinate.

Return value

An angle between -π and π.

Examples

Angle of a pointTry it yourself
const toDeg = (r) => (r * 180) / Math.PI;
console.log(toDeg(Math.atan2(1, 1)), toDeg(Math.atan2(1, -1)));

Output

45 135
Direction in degrees, 0 to 359Try it yourself
const heading = (dx, dy) => (Math.round((Math.atan2(dy, dx) * 180) / Math.PI) + 360) % 360;
console.log(heading(0, 1), heading(-1, 0));

Output

90 180

Version history

VersionChange
JavaScript ES1Added

Was this page helpful?