Javascript Reference - JavaScript tan() Method








The tan() method returns a number that represents the tangent of an angle.

Browser Support

tan() Yes Yes Yes Yes Yes

Syntax

Math.tan(x);

Parameter Values

Parameter Description
x Required. A number representing an angle in radians




Return Value

A Number representing the tangent of an angle.

Example

The following code shows how to calculates the tangent of a number.

<html>
<body>
  <script language="JavaScript">
    function doMath() {<!--from   ww w  .  java 2 s . c om-->
      var inputNum1 = document.form1.input1.value;
      var result = Math.tan(inputNum1);
      document.form1.answer.value = result;
    }
  </script>
  <form name=form1>
    This example calculates the tanget of the entered number. <br>
    <br> Enter Number: <input type="text" name="input1" size=10>
    <input type="button" value="Calculate" onClick='doMath()'> <br>
    The tangent is: <input type="text" name="answer" size=20>
  </form>
</body>
</html>

Click to view the demo