JavaScript Math.acos()
Syntax & Examples


Math.acos() static-method

The Math.acos() method in JavaScript returns the arccosine (inverse cosine) of a number. The method returns a value in radians, which is between 0 and π (inclusive).


Syntax of Math.acos()

The syntax of Math.acos() static-method is:

Math.acos(x)

This acos() static-method of Math returns the arccosine of x.

Parameters

ParameterOptional/RequiredDescription
xrequiredA number between -1 and 1. If the value of x is outside this range, the method returns NaN.

Return Type

Math.acos() returns value of type Number.



✐ Examples

1 Using Math.acos() with a positive number

In JavaScript, we can use the Math.acos() method to get the arccosine of a positive number.

For example,

  1. We call the Math.acos() method with a positive number x.
  2. The arccosine value is returned and stored in the variable result.
  3. We log result to the console using console.log() method.

JavaScript Program

const x = 0.5;
const result = Math.acos(x);
console.log(result);

Output

1.0471975511965979

2 Using Math.acos() with zero

In JavaScript, we can use the Math.acos() method to get the arccosine of zero.

For example,

  1. We call the Math.acos() method with zero x.
  2. The arccosine value is returned and stored in the variable result.
  3. We log result to the console using console.log() method.

JavaScript Program

const x = 0;
const result = Math.acos(x);
console.log(result);

Output

1.5707963267948966

3 Using Math.acos() with a negative number

In JavaScript, we can use the Math.acos() method to get the arccosine of a negative number.

For example,

  1. We call the Math.acos() method with a negative number x.
  2. The arccosine value is returned and stored in the variable result.
  3. We log result to the console using console.log() method.

JavaScript Program

const x = -0.5;
const result = Math.acos(x);
console.log(result);

Output

2.0943951023931957

Summary

In this JavaScript tutorial, we learned about acos() static-method of Math: the syntax and few working examples with output and detailed explanation for each example.