What is Math.acos() in JavaScript?
In JavaScript, Math is a built-in object that contains different methods and properties to perform mathematical operations. It contains a function acos(), which is used to compute the arc cosine of a specified number. This is also known as the inverse cosine of a number.
Syntax
Math.acos(param);
Parameter
param: This is a number that represents the cosine value. It is the input value of typeNumberfor which we want to find theacos(). Its range is:- -1 <= param <= 1
Numberin JavaScript is a 64-bit double-precision value which is the same asdoublein C# or Java.
Return value
-
Number: This returns the angle θ whose cosine is equal to the givenparam. It is of theNumbertype. Its range is:- 0 <= θ <= π (radians)
-
NaN: The function returnsNaNif:param< -1param> 1
Radians can be converted to degrees with the formula:
- Degrees = Radians × 180 / π
where
π= 3.14159, approximately.
Example
console.log("acos(-1) = " + Math.acos(-1));console.log("acos(0) = " + Math.acos(0));console.log("acos(1) = " + Math.acos(1));console.log("acos(0.5) = " + Math.acos(0.5));console.log("acos(-2) = " + Math.acos(-2));console.log("acos(2) = " + Math.acos(2));