Javascript Reference - JavaScript atan() Method








The atan() method returns the arctangent value between -PI/2 and PI/2 radians.

Browser Support

atan() Yes Yes Yes Yes Yes

Syntax

Math.atan(x);

Parameter Values

Parameter Description
x Required. A number




Return Value

It returns the arctangent value between -PI/2 and PI/2 radians.

It returns NaN if the value is empty.

Example

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

<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
  function doMath() {<!--from ww  w  . ja  v  a  2s .  c  o m-->
    var inputNum = document.form1.input.value;
    var result = Math.atan(inputNum);
    document.form1.answer.value = result;
  }
</script>
</head>
<body>
  <form name=form1>
    This example calculates the arctangent of the input number. <br>
    <br> Enter Number: <input type="text" name="input" size=10>
    <input type="button" value="Calculate" onClick='doMath()'> <br>
    The arctan is: <input type="text" name="answer" size=10>
  </form>
</body>
</html>

Click to view the demo