C-Sharp | Java | Python | Swift | GO | WPF | Ruby | Scala | F# | JavaScript | SQL | PHP | Angular | HTML
JavaScript Math atan() methodThe JavaScript math atan() method returns the arctangent of the given number in the form of radians. The value returned by atan() method lies between -Math.PI/2 to Math.PI/2. SyntaxThe atan() method is represented by the following syntax: Math.atan(num) Parameternum - A number. ReturnThe arctangent of the number. JavaScript Math atan() method exampleHere, we will understand atan() method through various examples. Example 1Let's see a simple example of atan() method. <script> document.writeln(Math.atan(-1)+"<br>"); document.writeln(Math.atan(0)+"<br>"); document.writeln(Math.atan(0.5)+"<br>"); document.writeln(Math.atan(1)); </script> Output: -0.7853981633974483 0 0.4636476090008061 0.7853981633974483 Example 2Let's see an example of atan() method that contains infinity as an argument. <script> document.writeln(Math.atan(Infinity)+"<br>"); document.writeln(Math.atan(-Infinity)); </script> Output: 1.5707963267948966 -1.5707963267948966 Example 3Here, you can test atan() method with your own test cases. <script> function display() { var x=document.getElementById("num").value; document.getElementById("result").innerHTML=Math.atan(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
|