JavaScript Math atan() method is used to calculate the arctangent of a number.
Syntax
Math.atan(num)
Parameters
num(required): It is a number whose arctangent you want to calculate.
Return value
Returns the numeric value between -pi/2 and pi/2 radians.
If the passed value is empty or not numeric, the method returns NaN.
Visual RepresentationExample 1: How to Use Math atan() Method
let a = 1; //positive value
let b = 3.2; //float value
let c = -4; //negative value
let d = 0;
console.log(Math.atan(a));
console.log(Math.atan(b));
console.log(Math.atan(c));
console.log(Math.atan(d));
Output
0.7853981633974483
1.2679114584199251
-1.3258176636680326
0
Example 2: Passing an empty and Non-Numeric Argument
console.log(Math.atan()); //empty value
console.log(Math.atan("AppDividend")); //non-numeric value
Output
NaN
NaN
Example 3: Passing Infinity
let a = Math.atan(Infinity);
console.log(a);
let b = Math.atan(-Infinity); //negative Infinity
console.log(b);
Output
1.5707963267948966
-1.5707963267948966
Browser compatibility
- Google Chrome 1 and above
- Edge 12 and above
- Firefox 1 and above
- Opera 3 and above
- Safari 1 and above
Ankit Lathiya is a Master of Computer Application by education and Android and Laravel Developer by profession and one of the authors of this blog. He is also expert in JavaScript and Python development.