The tan() method computes the trigonometric tangent of the specified angle and returns it.
Example
tan() Syntax
The syntax of the Math.tan() method is:
Math.tan(angle)
Here, tan() is a static method. Hence, we are accessing the method using the class name, Math.
tan() Parameter
The tan() method takes a single parameter:
angle- in radians whose tangent value is to be calculated
tan() Return Value
The tan() method returns:
- tangent of a given
angle(in radians) - NaN (Not a Number) for a non-numeric argument
Example 1: JavaScript Math.tan()
In the above example,
Math.tan(5)- calculates the tangent of5Math.tan(-2)- calculates the tangent of-2
Example 2: Math.tan() with Math Constants
In the above example, we have used the tan() method to compute the tangent of the math constant PI.
Here, the output -1.2246467991473532e-16 represents -1.2246467991473532 * 10-16.
Example 3: Math.tan() with Non-Numeric argument
In the above example, we have used the tan() method with a string argument.
When using a string argument, the method gives us NaN as output.
Example 4: Math.tan() with Infinity argument
The tan() method doesn't treat -Infinity and Infinity as numbers and produces NaN as output.
This is because the tangent of an angle can never be infinite.
Recommended readings: