JavaScript Math.atan() Method

Beginner
5 min read
Updated: Nov 2026
3 examples
Math

Definition

Math.atan(x) returns the arc tangent (inverse tangent) of a number. It answers: which angle has this tangent? The angle is in radians, between -π/2 and π/2.

Math is built into JavaScript. Call the method directly. It is not a constructor, so never write new Math().

Syntax

Call Math.atan() like this. Start with this line.

JavaScript
Math.atan(x)
CallWhat it does
Math.atan(x)Returns the arc tangent of x, in radians.

Built into JavaScript. Call Math.atan() on the Math object — no import required.

Library declarations
JavaScript
Math.atan(x)
JavaScript
interface Math {
  atan(x: number): number;
}

Parameters

ParameterDescription
xRequired. A number. Other values are converted to a number first.

Return Value

Return ValueDescription
numberThe angle in radians, between -π/2 and π/2. Returns NaN if x cannot be turned into a number.

JavaScript Examples

Example 1 — Basic Use

Any number is allowed. The result is an angle in radians.

JavaScript
console.log(Math.atan(0));          // 0
console.log(Math.atan(1));          // 0.7853981633974483
console.log(Math.atan(-1));         // -0.7853981633974483
console.log(Math.atan(Infinity));   // 1.5707963267948966
Try It Yourself

How It Works

  1. Tangent 0. The angle is 0.
  2. Tangent 1. The angle is π / 4, about 0.7854 (45 degrees).
  3. Negative. A negative tangent gives a negative angle.
  4. Infinity. The result stops at π / 2 (90 degrees).

Example 2 — Slope to Angle in Degrees

Turn a slope (rise over run) into an angle in degrees.

JavaScript
var rise = 3;
var run = 4;

var slope = rise / run;
var degrees = Math.atan(slope) * 180 / Math.PI;

console.log(slope);               // 0.75
console.log(degrees.toFixed(1));  // 36.9
Try It Yourself

How It Works

  1. Find the slope. rise / run is 0.75.
  2. Apply atan. Math.atan(0.75) gives the angle in radians.
  3. Convert. Multiply by 180 / Math.PI. The angle is about 36.9 degrees.

Example 3 — Why atan() Loses the Quadrant

Two different points can give the same slope. atan2() can tell them apart.

JavaScript
var a = Math.atan(1 / 1);        // point (1, 1)
var b = Math.atan(-1 / -1);      // point (-1, -1)
console.log(a === b);            // true

var c = Math.atan2(1, 1);
var d = Math.atan2(-1, -1);
console.log(c.toFixed(4));       // 0.7854
console.log(d.toFixed(4));       // -2.3562
Try It Yourself

How It Works

  1. Same slope. Both points give a slope of 1, so Math.atan returns the same angle.
  2. Different points. But the points are in opposite quadrants.
  3. Use atan2. Math.atan2 keeps the signs. It returns 0.7854 for the first and -2.3562 for the second.

Browser & Runtime Support

Math.atan() has been part of JavaScript since ES1 and is Baseline Widely available everywhere.

✓ Baseline · ES1

Math.atan()

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.atan Excellent

Bottom line: Use Math.atan() freely. It works in all browsers and runtimes.

Frequently Asked Questions

Math.atan(x) returns the angle, in radians, whose tangent is x. For example, Math.atan(1) is about 0.7854, which is 45 degrees.
No. It returns radians. Multiply by 180 / Math.PI to get degrees.
Math.atan(y / x) loses the signs of x and y. Math.atan2(y, x) keeps them and gives the correct angle in all four quadrants.
It returns about 1.5708, which is Math.PI / 2. The result never goes past this limit.
Any number. There is no invalid range, unlike Math.asin() and Math.acos().

Next: atan2()

Learn how to find the angle of a point from the x-axis.

atan2() 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.

8 people found this page helpful