JavaScript: Math tan() function
This JavaScript tutorial explains how to use the math function called tan() with syntax and examples.
Description
In JavaScript, tan() is a function that is used to return the tangent of a number. Because the tan() function is a static function of the Math object, it must be invoked through the placeholder object called Math.
Syntax
In JavaScript, the syntax for the tan() function is:
Math.tan(number);
Parameters or Arguments
- number
- The number used to calculate the tangent. It is the value of an angle expressed in radians.
Returns
The tan() function returns the tangent of a number.
Note
- To convert degrees to radians, multiply by 2π/360 or 0.017453293.
- Math is a placeholder object that contains mathematical functions and constants of which tan() is one of these functions.
Example
Let's take a look at an example of how to use the tan() function in JavaScript.
For example:
console.log(Math.tan(2));
console.log(Math.tan(0));
console.log(Math.tan(-0.9));
In this example, we have invoked the tan() function using the Math class.
We have written the output of the tan() function to the web browser console log, for demonstration purposes, to show what the tan() function returns.
The following will be output to the web browser console log:
-2.185039863261519 0 -1.2601582175503392
In this example, the first output to the console log returned -2.185039863261519 which is the tangent of 2.
The second output to the console log returned 0 which is the tangent of 0.
The third output to the console log returned -1.2601582175503392 which is the tangent of -0.9.
Advertisements