Math cos() Method - Javascript Math

Javascript examples for Math:cos

Description

The cos() method returns the cosine of a number.

Parameter Values

Parameter Description
x Required. A number

Return Value:

A Number, from -1 to 1, representing the cosine of an angle, or NaN if the value is empty

The following code shows how to return the cosine of a number:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<button onclick="myFunction()">Test</button>

<p id="demo"></p>

<script>
function myFunction() {/*from   w  w w. j a  va 2  s . c  o  m*/
    var a = Math.cos(Math.PI);
    var b = Math.cos(2 * Math.PI);
    document.getElementById("demo").innerHTML = a + "<br>" + b;
}
</script>

</body>
</html>

Related Tutorials