Math.cos() Method - Math Functions

Math.cos() method of Math Functions in Javascript.
How to get the cosine value of a number in javascript?

Explanation

Object: Math
Method: Math.cos()
Description: To get the cosine value for a number specified as radians. The function returns a value between -1 and 1 for the given number. The below example will get Cosine value for numbers 0, PI using Math Functions.

Example:


<script type="text/javascript">
document.write('Cosine of 0 is::'+Math.cos(0));
document.write('
');
document.write('Cosine of PI is::'+Math.cos(Math.PI));
</script>

Result:




In the above example,
  • First the cosine value of "0" is got as "1".
  • To get the cosine value of "PI" we have used "Math.PI" function, it returns "-1".

Ask Questions

Ask Question