Math.cos( ) In JavaScript

The Math.cos() function in Javascript is used to return the cosine of a number.
The Math.cos() method returns a numeric value between -1 and 1, which represents the cosine of the angle given in radians. The cos() is a static method of Math, therefore, it is always used as Math.cos(), rather than as a method of a Math object created.

Syntax:

Math.cos(value)

Parameters: This function accepts single parameter which is a number given in radians.



Returns: The Math.cos() function returns the cosine of the given numbers which range from -1 to 1.

Examples:

  1. When zero is passed as a parameter.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script type="text/javascript">
       document.write("Output : " + Math.cos(0));
    </script>

    chevron_right

    
    

    Output:

    Output : 1
  2. When 1 is passed as a parameter.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script type="text/javascript">
       document.write("Output : " + Math.cos(1));
    </script>

    chevron_right

    
    

    Output:

    Output : 0.5403023058681398
  3. When PI is passed as a parameter.
    filter_none

    edit
    close

    play_arrow

    link
    brightness_4
    code

    <script type="text/javascript">
       document.write("Output : " + Math.cos(Math.PI));
    </script>

    chevron_right

    
    

    Output:

    Output : -1

Supported Browsers: The browsers supported by JavaScript Math.cos( ) function are listed below:

  • Google Chrome
  • Internet Explorer
  • Firefox
  • Opera
  • Safari


My Personal Notes arrow_drop_up

I am a technology enthusiast who has a keen interest in programming I am pursuing Engineering in Computer Science from GEU, Dehradun I like to unwind by watching movies and English sitcomsI have a keen interest in music

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



Improved By : skyridetim



Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.