JavaScript Math.atan()
Syntax & Examples


Math.atan() static-method

The Math.atan() method in JavaScript returns the arctangent (inverse tangent) of a number. The method returns a value in radians, which is between -π/2 and π/2 (inclusive).


Syntax of Math.atan()

The syntax of Math.atan() static-method is:

Math.atan(x)

This atan() static-method of Math returns the arctangent of x.

Parameters

ParameterOptional/RequiredDescription
xrequiredA number representing the value for which the arctangent is to be returned.

Return Type

Math.atan() returns value of type Number.



✐ Examples

1 Using Math.atan() with a positive number

In JavaScript, we can use the Math.atan() method to get the arctangent of a positive number.

For example,

  1. We call the Math.atan() method with a positive number x.
  2. The arctangent value is returned and stored in the variable result.
  3. We log result to the console using console.log() method.

JavaScript Program

const x = 1;
const result = Math.atan(x);
console.log(result);

Output

0.7853981633974483

2 Using Math.atan() with zero

In JavaScript, we can use the Math.atan() method to get the arctangent of zero.

For example,

  1. We call the Math.atan() method with zero x.
  2. The arctangent value is returned and stored in the variable result.
  3. We log result to the console using console.log() method.

JavaScript Program

const x = 0;
const result = Math.atan(x);
console.log(result);

Output

0

3 Using Math.atan() with a negative number

In JavaScript, we can use the Math.atan() method to get the arctangent of a negative number.

For example,

  1. We call the Math.atan() method with a negative number x.
  2. The arctangent value is returned and stored in the variable result.
  3. We log result to the console using console.log() method.

JavaScript Program

const x = -1;
const result = Math.atan(x);
console.log(result);

Output

-0.7853981633974483

Summary

In this JavaScript tutorial, we learned about atan() static-method of Math: the syntax and few working examples with output and detailed explanation for each example.