Home >>JavaScript Math Reference >JavaScript cos() Method
JavaScript cos() method is used to return the cosine value of a given input number. It returns a numeric value as the result between the range of -1 and 1 which represents the cosine of the angle.
Syntax:Math.cos(x)
Parameter | Description |
---|---|
x | This is a required parameter. It defines the given input number. |
Method | Chrome | Edge | Firefox | Safari | Opera |
---|---|---|---|---|---|
cos() | Yes | Yes | Yes | Yes | Yes |
<html> <body> <p>Click the button to see the Output.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = Math.cos(5); } </script> </body> </html>
Click the button to see the Output.
<html> <body> <p>Click the button to see the Output.</p> <button onclick="myFunction1()">Try it</button> <p id="demo1"></p> <script> function myFunction1() { document.getElementById("demo1").innerHTML = Math.cos(10); } </script> </body> </html>
Click the button to see the Output.