JavaScript Math.acos() Method

Definition
Math.acos(x) returns the arc cosine (inverse cosine) of a number. It answers: which angle has this cosine? The angle is given in radians, from 0 to π.
Math is built into JavaScript. Call the method directly. It is not a constructor, so never write new Math().
Syntax
Call Math.acos() like this. Start with this line.
| Call | What it does |
|---|
Math.acos(x) | Returns the arc cosine of x, in radians. |
Built into JavaScript. Call Math.acos() on the Math object — no import required.
Library declarations
interface Math {
acos(x: number): number;
}
Parameters
| Parameter | Description |
|---|
| x | Required. A number from -1 to 1. Numbers outside this range return NaN. |
Return Value
| Return Value | Description |
|---|
| number | The angle in radians, from 0 to π (about 3.14159). Returns NaN if x is below -1 or above 1. |
JavaScript Examples
Example 1 — Basic Use
Pass a number from -1 to 1. You get an angle in radians.
console.log(Math.acos(1)); // 0
console.log(Math.acos(0.5)); // 1.0471975511965979
console.log(Math.acos(0)); // 1.5707963267948966
console.log(Math.acos(-1)); // 3.141592653589793
console.log(Math.acos(2)); // NaN
0
1.0471975511965979
1.5707963267948966
3.141592653589793
NaN
How It Works
- Cosine 1. The angle with cosine
1 is 0. - Cosine 0.
Math.acos(0) is about 1.5708, which is π / 2 (90 degrees). - Cosine -1. The result is
Math.PI (180 degrees). - Out of range.
2 is not a valid cosine, so the result is NaN.
Example 2 — Radians to Degrees
Most people think in degrees. Convert the radians with 180 / Math.PI.
function toDegrees(radians) {
return radians * 180 / Math.PI;
}
var angle = Math.acos(0.5);
console.log(angle); // 1.0471975511965979
console.log(toDegrees(angle).toFixed(1)); // 60.0
console.log(toDegrees(Math.acos(0))); // 90
1.0471975511965979
60.0
90
How It Works
- Get radians.
Math.acos(0.5) returns about 1.0472 radians. - Convert. Multiply by
180 / Math.PI to get degrees. - Round it.
toFixed(1) hides tiny floating-point noise and shows 60.0.
Example 3 — Angle Between Two Vectors
Use the dot product and the lengths of two vectors to find the angle between them.
var a = { x: 1, y: 0 };
var b = { x: 1, y: 1 };
var dot = a.x * b.x + a.y * b.y;
var lengthA = Math.hypot(a.x, a.y);
var lengthB = Math.hypot(b.x, b.y);
var radians = Math.acos(dot / (lengthA * lengthB));
console.log(radians.toFixed(4)); // 0.7854
console.log((radians * 180 / Math.PI).toFixed(1)); // 45.0
How It Works
- Dot product.
dot is 1 for these two vectors. - Lengths.
Math.hypot gives the length of each vector: 1 and about 1.414. - Divide.
dot / (lengthA * lengthB) is the cosine of the angle (about 0.7071). - Apply acos.
Math.acos turns that cosine back into the angle: 45 degrees.
Compatibility
Browser & Runtime Support
Math.acos() has been part of JavaScript since ES1 and is Baseline Widely available everywhere.
✓ Baseline · ES1
Math.acos()
Supported in every browser and Node.js version. No polyfill is needed.
99% Modern browser support
Google Chrome Supported · Desktop & Mobile
Full support
Mozilla Firefox Supported · Desktop & Mobile
Full support
Apple Safari Supported · macOS & iOS
Full support
Microsoft Edge Supported · Chromium
Full support
Internet Explorer No native support · Use a polyfill
Polyfill
Opera Supported · Modern versions
Full support
Samsung Internet Supported · Android
Full support
Bun Supported · JavaScript runtime
Supported
Deno Supported · JavaScript runtime
Supported
Node.js Supported · Server runtime
Supported
Android WebView Supported · Modern WebView
Full supportMath.acos Excellent
Bottom line: Use Math.acos() freely. It works in all browsers and runtimes.
Frequently Asked Questions
Math.acos(x) returns the angle, in radians, whose cosine is x. For example, Math.acos(1) is 0 and Math.acos(-1) is Math.PI.
No. It returns radians. Convert with radians * 180 / Math.PI. For example, Math.acos(0.5) is about 60 degrees.
A cosine is always between -1 and 1, so no angle has a cosine of 2. Inputs outside -1 to 1 return NaN.
The result is between 0 and Math.PI (about 3.14159) for valid inputs.
Math.cos(angle) takes an angle and returns a ratio. Math.acos(ratio) does the reverse: it takes a ratio and returns the angle.
About the author
Developer, cloud engineer, and technical writer
I write practical tutorials so students and working developers can learn by doing—from databases and APIs to deployment on AWS.
9 people found this page helpful