JavaScript Math atan()

The JavaScript Math.atan() function returns the arctangent of a number in radians.

Syntax of the Math.atan() function is:

Math.atan(x)

atan(), being a static method, is called using the Math class name.


Math.atan() Parameters

The Math.atan() function takes in:

  • x - A number whose arctangent is required.

Return value from Math.atan()

  • Returns the arctangent of a number between -π/2 and π/2 radians.

Example: Using Math.atan()

// using Math.atan()
var num = Math.atan(1);
console.log(num); // 0.7853981633974483 (pi/4)

var num = Math.atan(0);
console.log(num); // 0

var num = Math.atan(Infinity);
console.log(num); // 1.5707963267948966 (pi/2)

var num = Math.atan(Math.pow(3, 0.5)); // square root of 3
console.log(num); // 1.0471975511965976 (pi/3)

Output

0.7853981633974483
0
1.5707963267948966
1.0471975511965976

Recommended readings: