Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / JavaScript

Math.tan: tangent in radians

Math.tan converts its argument to Number and returns an approximation of its tangent, interpreting the angle in radians.

Version: ECMAScript 1 onward; example target: Node.js 24.22.2

Syntax

Math.tan(x)

Math.tan(x) applies ToNumber and computes the tangent of a finite angle in radians. Math.tan(+0) returns +0, and Math.tan(-0) returns -0; for other finite values the result is an implementation-dependent binary64 approximation. Tangent has period π and is not bounded to a fixed range.

NaN, Infinity, -Infinity, and a missing argument produce NaN. A numeric string is converted, while a Symbol or BigInt throws TypeError; an object can run conversion code. Near odd multiples of π/2 the mathematical function has asymptotes, but approximated π and input normally yield a very large finite value, not guaranteed Infinity.

The function has existed since ECMAScript 1 and is not a constructor. Convert degrees with degrees * Math.PI / 180; the example produces approximately 1 for 45°. Do not test proximity to an asymptote by exact equality, and account for precision loss when reducing enormous angles.

Examples

console.log(Math.tan(0), Math.tan(Math.PI / 4).toFixed(6));
console.log(Math.tan(45 * Math.PI / 180).toFixed(6));
console.log(Object.is(Math.tan(-0), -0));
console.log(Number.isNaN(Math.tan(Infinity)), Number.isNaN(Math.tan()));
try { Math.tan(1n); } catch (error) { console.log(error instanceof TypeError); }

Result

0 1.000000
1.000000
true
true true
true

Math.tan → radians, 45° conversion, and preserved -0

Sources