How to get the arccosine (in radians) of a number in JavaScript?

JavascriptWeb DevelopmentFront End Technology

To get the arccosine (in radians) of a number, use the Math.acos() method. This method returns the arccosine in radians of a number. The acos() method returns a numeric value between 0 and pi radians for x between -1 and 1. If the value of a number is outside this range, it returns NaN.

You can try to run the following code to get the arccosine (in radians) in JavaScript −

Example

<html>
   <head>
      <title>JavaScript Math acos() Method</title>
   </head>
   
   <body>
      <script>
         var value = Math.acos(-1);
         document.write("First Value : " + value );

         var value = Math.acos(null);
         document.write("<br />Second Value : " + value );

         var value = Math.acos(30);
         document.write("<br />Third Value : " + value );

         var value = Math.acos("Demo Text");
         document.write("<br />Fourth Value : " + value );
      </script>
   </body>
   
</html>

Output

First Value : 3.141592653589793
Second Value : 1.5707963267948966
Third Value : NaN
Fourth Value : NaN
raja
Published on 16-Feb-2018 06:34:39
Advertisements