C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Math tan() methodThe JavaScript math tan() method returns the tangent of the given number that represents the tangent of an angle. SyntaxThe tan() method is represented by the following syntax: Math.tan(num) Parameternum - A number. ReturnA number that represents the tangent of the angle. JavaScript Math tan() method exampleHere, we will understand tan() method through various examples. Example 1Let's see a simple example of tan() method. <script> document.writeln(Math.tan(1)+"<br>"); document.writeln(Math.tan(2)); </script> Output: 1.5574077246549023 -2.185039863261519 Example 2In this example, we will use tan() method with negative numbers. <script> document.writeln(Math.tan(-1)+"<br>"); document.writeln(Math.tan(-0.5)); </script> Output: -1.5574077246549023 -0.5463024898437905 Example 3Let's see tan() method with some different test cases. <script> document.writeln(Math.tan(0)+"<br>"); document.writeln(Math.tan(Math.PI)); </script> Output: 0 -1.2246467991473532e-16 Example 4Here, you can test tan() method with your own test cases. <script> function display() { var x=document.getElementById("num").value; document.getElementById("result").innerHTML=Math.tan(x); } </script> <form> Enter a number: <input type="text" id="num"> <input type="button" onclick="display()" value="submit"> </form> <p><span id="result"></span></p>
Next TopicJavaScript Math
|