Computer >> Computer tutorials >  >> Programming >> Javascript

How to get the tangent of a number in JavaScript?


To get the tangent of a number in JavaScript, use the Math.tan() method. This method returns the tangent of a number. The tan method returns a numeric value that represents the tangent of the angle.

Example

You can try to run the following code to get the tangent of a number −

<html>
   <head>
      <title>JavaScript Math tan() Method</title>
   </head>
   <body>
      <script>
         var value = Math.tan( -30 );
         document.write("First Value : " + value );
         
         var value = Math.tan( 90 );
         document.write("<br />Second Value : " + value );

         var value = Math.tan( 45 );
         document.write("<br />Third Value : " + value );

         var value = Math.tan( Math.PI/180 );
         document.write("<br />Fourth Value : " + value );
      </script>
   </body>
</html>