To get the cosine of a number in JavaScript, use the Math.cos() method. The cos method returns a numeric value between -1 and 1, which represents the cosine of the angle.
Example
You can try to run the following code to get the cosine of a number −
<html>
<head>
<title>JavaScript Math cos() Method</title>
</head>
<body>
<script>
var value = Math.cos(90);
document.write("First Value : " + value );
value = Math.cos(30);
document.write("<br />Second Value : " + value );
value = Math.cos(-1);
document.write("<br />Third Value : " + value );
value = Math.cos(2*Math.PI);
document.write("<br />Fourth Value : " + value );
</script>
</body>
</html>