JavaScript Math.tan()
Syntax & Examples


Math.tan() static-method

The Math.tan() static method in JavaScript returns the tangent of a number. The number is assumed to be in radians.


Syntax of Math.tan()

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

Math.tan(x)

This tan() static-method of Math returns the tangent of the given number x, where x is in radians.

Parameters

ParameterOptional/RequiredDescription
xrequiredA number representing an angle in radians whose tangent is to be calculated.

Return Type

Math.tan() returns value of type Number.



✐ Examples

1 Using Math.tan() with a positive angle

In JavaScript, we can use the Math.tan() method to calculate the tangent of a positive angle given in radians.

For example,

  1. We pass the angle Math.PI / 4 radians (which is 45 degrees) to the Math.tan() method.
  2. The result, approximately 1, indicates the tangent of 45 degrees.
  3. We log the result to the console using the console.log() method.

JavaScript Program

const result = Math.tan(Math.PI / 4);
console.log(result);

Output

1

2 Using Math.tan() with zero

In JavaScript, we can use the Math.tan() method to calculate the tangent of zero radians.

For example,

  1. We pass the angle 0 radians to the Math.tan() method.
  2. The result, 0, indicates the tangent of zero degrees.
  3. We log the result to the console using the console.log() method.

JavaScript Program

const result = Math.tan(0);
console.log(result);

Output

0

3 Using Math.tan() with a negative angle

In JavaScript, we can use the Math.tan() method to calculate the tangent of a negative angle given in radians.

For example,

  1. We pass the angle -Math.PI / 4 radians (which is -45 degrees) to the Math.tan() method.
  2. The result, approximately -1, indicates the tangent of -45 degrees.
  3. We log the result to the console using the console.log() method.

JavaScript Program

const result = Math.tan(-Math.PI / 4);
console.log(result);

Output

-1

Summary

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