Math.atan()
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The Math.atan() static method returns the inverse tangent (in radians) of a number, that is
Try it
Syntax
js
Math.atan(x)
Parameters
x-
A number.
Return value
The inverse tangent (angle in radians between and , inclusive) of x. If x is Infinity, it returns . If x is -Infinity, it returns .
Description
Because atan() is a static method of Math, you always use it as Math.atan(), rather than as a method of a Math object you created (Math is not a constructor).
Examples
Using Math.atan()
js
Math.atan(-Infinity); // -1.5707963267948966 (-π/2)
Math.atan(-0); // -0
Math.atan(0); // 0
Math.atan(1); // 0.7853981633974483 (π/4)
Math.atan(Infinity); // 1.5707963267948966 (π/2)
// The angle that the line (0,0) -- (x,y) forms with the x-axis in a Cartesian coordinate system
const theta = (x, y) => Math.atan(y / x);
Note that you may want to avoid the theta function and use Math.atan2() instead, which has a wider range (between -π and π) and avoids outputting NaN for cases such as when x is 0.
Specifications
| Specification |
|---|
| ECMAScript® 2025 Language Specification # sec-math.atan |
Browser compatibility
BCD tables only load in the browser