Javascript Reference - JavaScript acos() Method








The acos() method returns the arccosine of a number.

Browser Support

acos() Yes Yes Yes Yes Yes

Syntax

Math.acos(x);

Parameter Values

Parameter Description
x Required. A number

Return Value

The returned value is between 0 and PI radians.

If the parameter is outside the range -1 to 1, the method will return NaN.

acos(-1) returns PI.





Example

The following code shows how to calculate the arccosine of a number.

<html>
<body>
  <script language="JavaScript">
    function doMath() {<!--from   www  .ja v a2 s.c  o m-->
      var inputNum = document.form1.input.value;
      var result = Math.acos(inputNum);
      document.form1.answer.value = result;
    }
  </script>
  <form name=form1>
    <br> Enter Number: <input type="text" name="input" size=10>
    <input type="button" value="Calculate" onClick='doMath()'> <br>
    The arccosine is: <input type="text" name="answer" size=10>
  </form>
</body>
</html>

Click to view the demo