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 type Number for which we want to find the acos(). Its range is:
    • -1 <= param <= 1

Number in JavaScript is a 64-bit double-precision value which is the same as double in C# or Java.

Return value

  • Number: This returns the angle θ whose cosine is equal to the given param. It is of the Number type. Its range is:

    • 0 <= θ <= π (radians)
  • NaN: The function returns NaN if:

    • param < -1
    • param > 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));