totn JavaScript

JavaScript: Math atan() function

This JavaScript tutorial explains how to use the math function called atan() with syntax and examples.

Description

In JavaScript, atan() is a function that is used to return the arc tangent (in radians) of a number. Because the atan() function is a static function of the Math object, it must be invoked through the placeholder object called Math.

Syntax

In JavaScript, the syntax for the atan() function is:

Math.atan(number);

Parameters or Arguments

number
The number used to calculate the arc tangent in radians.

Returns

The atan() function returns the arc tangent of a number and the result is expressed in radians.

Note

  • Math is a placeholder object that contains mathematical functions and constants of which atan() is one of these functions.

Example

Let's take a look at an example of how to use the atan() function in JavaScript.

For example:

console.log(Math.atan(0.75));
console.log(Math.atan(-0.9));
console.log(Math.atan(2));

In this example, we have invoked the atan() function using the Math class.

We have written the output of the atan() function to the web browser console log, for demonstration purposes, to show what the atan() function returns.

The following will be output to the web browser console log:

0.6435011087932844
-0.7328151017865066
1.1071487177940904

In this example, the first output to the console log returned 0.6435011087932844 which is the arc tangent of 0.75. The second output to the console log returned -0.7328151017865066 which is the arc tangent of -0.9. The third output to the console log returned 1.1071487177940904 which is the arc tangent of 2.

The result from the atan() function is expressed in radians.