Home >>JavaScript Math Reference >JavaScript cos() Method

JavaScript cos() Method

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 Values

Parameter Description
x This is a required parameter. It defines the given input number.

Browser Support

Method Chrome Edge Firefox Safari Opera
cos() Yes Yes Yes Yes Yes
Here is an example of JavaScript cos() method:
<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>
Output:

Click the button to see the Output.

Example 2:
<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>
Output:

Click the button to see the Output.


No Sidebar ads