How to Use the Math.atan() Method in JavaScript

09/30/2021

Contents

In this article, you will learn how to use the Math.atan() method in JavaScript.

Using the Math.atan() method in JavaScript

The Math.atan() method is a built-in function in JavaScript that returns the arctangent (in radians) of a given number. The input parameter can be any number, positive or negative.

Syntax

The syntax for using the Math.atan() method is:

Math.atan(x)

where x is the input parameter that represents the tangent of an angle.

Examples

Using Math.atan() to calculate the arctangent of a number

const x = 0.5;
const arctangent = Math.atan(x);
console.log(arctangent); // 0.4636476090008061

In this example, the input parameter is 0.5, which represents the tangent of an angle. The output is the arctangent of 0.5 in radians, which is approximately 0.4636.

Using Math.atan() with a negative value

const x = -0.7;
const arctangent = Math.atan(x);
console.log(arctangent); // -0.6107259643892086

In this example, the input parameter is -0.7, which represents the tangent of an angle. The output is the arctangent of -0.7 in radians, which is approximately -0.6107.

Note: The output of the Math.atan() method is always in radians. If you want to convert the result to degrees, you can use the following formula:

degrees = radians * (180 / Math.PI)

where radians is the output of the Math.atan() method.