![]() |
VOOZH | about |
Given a radian value, our task is to find a tangent using JavaScript. Tangent (tan) is a trigonometric function which is the ratio of the length of the side opposite to an angle to the length of the adjacent side in a right triangle.
Example:
Input: 45 degrees
Output: 1
Below are the approaches to find the tangent of a given radian value using JavaScript:
Table of Content
Create a function that takes a radian parameter. Inside the function, use the Math.tan() function provided by JavaScript's Math object to calculate the tangent of the given radian value. Return the calculated tangent value.
Example: The example below shows finding the tangent of a given radian value Using Math.tan() Function.
Tangent of 60 radians is: 0.320040389379563
Time complexity: O(1).
Space complexity: O(1).
Create a function that takes a radian parameter. Inside the function, use the Math.sin() function to calculate the sine of the given radian value and use the Math.cos() function to calculate the cosine of the radian value. Divide the sine value by the cosine value to obtain the tangent of the given radian value. Return the calculated tangent value.
Example: The example below shows finding the tangent of a given radian value Using Math.tan() Function.
Tangent of 45 radians is: 1.6197751905438615
Time complexity: O(1).
Space complexity: O(1).