What is Math.atan() in JavaScript?
In JavaScript, Math is a built-in object that contains different methods and properties used to perform mathematical operations. It contains an atan() function, which is used to compute a specified number’s arc tangent. This is also known as the inverse tangent of a number.
Syntax
Math.atan(param);
Parameter
param: This is a number that represents the tangent value. It is the input value ofNumbertype for which we want to find theatan().
Numberin JavaScript is a 64-bit double-precision value which is the same asdoublein C# or Java.
Return value
Number: It returns the angle θ whose tangent is equal to the givenparam. It is ofNumbertype. Its range is:-
- π/2 <= θ <= π/2 (radians)
-
To convert radians to degrees, use the following formula.
- Degrees = Radians × 180 / π
where
π= 3.14159, approximately.
Example
console.log("atan(-1) = " + Math.atan(-1));console.log("atan(0) = " + Math.atan(0));console.log("atan(1) = " + Math.atan(1));console.log("atan(∞) = " + Math.atan(Infinity));console.log("atan(-∞) = " + Math.atan(-Infinity));