JavaScript Math atan() Method

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 RepresentationVisual Representation of JavaScript Math atan() MethodExample 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 ArgumentPassing an empty and Non-Numeric Argument(Math Atan)

console.log(Math.atan()); //empty value
console.log(Math.atan("AppDividend")); //non-numeric value

Output

NaN
NaN

Example 3: Passing InfinityVisual Representation of 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

  1. Google Chrome 1 and above
  2. Edge 12 and above
  3. Firefox 1 and above
  4. Opera 3 and above
  5. Safari 1 and above

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.