metadata
title: Math.atan()
short-title: atan()
slug: Web/JavaScript/Reference/Global_Objects/Math/atan
page-type: javascript-static-method
browser-compat: javascript.builtins.Math.atan
sidebar: jsref
The Math.atan() static method returns the inverse tangent (in radians) of a number, that is
{{InteractiveExample("JavaScript Demo: Math.atan()")}}
// Calculates angle of a right-angle triangle in radians
function calcAngle(opposite, adjacent) {
return Math.atan(opposite / adjacent);
}
console.log(calcAngle(8, 10));
// Expected output: 0.6747409422235527
console.log(calcAngle(5, 3));
// Expected output: 1.0303768265243125
Syntax
Math.atan(x)
Parameters
x- : A number.
Return value
The inverse tangent (angle in radians between and , inclusive) of x. If x is {{jsxref("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()
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 {{jsxref("Math.atan2()")}} instead, which has a wider range (between -Ο and Ο) and avoids outputting NaN for cases such as when x is 0.
Specifications
{{Specifications}}
Browser compatibility
{{Compat}}
See also
- {{jsxref("Math.acos()")}}
- {{jsxref("Math.asin()")}}
- {{jsxref("Math.atan2()")}}
- {{jsxref("Math.cos()")}}
- {{jsxref("Math.sin()")}}
- {{jsxref("Math.tan()")}}
- CSS {{cssxref("atan()")}} function