JavaScript Math.acos() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

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.

JavaScript
Math.acos(x)
CallWhat 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
JavaScript
Math.acos(x)
JavaScript
interface Math {
  acos(x: number): number;
}

Parameters

ParameterDescription
xRequired. A number from -1 to 1. Numbers outside this range return NaN.

Return Value

Return ValueDescription
numberThe 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.

JavaScript
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
Try It Yourself

How It Works

  1. Cosine 1. The angle with cosine 1 is 0.
  2. Cosine 0. Math.acos(0) is about 1.5708, which is π / 2 (90 degrees).
  3. Cosine -1. The result is Math.PI (180 degrees).
  4. 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.

JavaScript
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
Try It Yourself

How It Works

  1. Get radians. Math.acos(0.5) returns about 1.0472 radians.
  2. Convert. Multiply by 180 / Math.PI to get degrees.
  3. 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.

JavaScript
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
Try It Yourself

How It Works

  1. Dot product. dot is 1 for these two vectors.
  2. Lengths. Math.hypot gives the length of each vector: 1 and about 1.414.
  3. Divide. dot / (lengthA * lengthB) is the cosine of the angle (about 0.7071).
  4. Apply acos. Math.acos turns that cosine back into the angle: 45 degrees.

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 support
Math.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.

Next: acosh()

Learn how to find the inverse hyperbolic cosine.

acosh() tutorial →

About the author

Mari Selvan M P
Mari Selvan M P 🔗

Developer, cloud engineer, and technical writer

  • Experience 12 years building web and cloud systems
  • Focus Full Stack Development, AWS, and Developer Education

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