Home » JavaScript Math cos() Method

JavaScript Math cos() Method

by Online Tutorials Library

JavaScript Math cos() method

The JavaScript math cos() method returns the cosine of the given number. The value returned by cos() method ranges -1 to 1, which represents the cosine of the angle.

Syntax

The cos() method is represented by the following syntax:

Parameter

num – A number.

Return

The cosine of a number.

JavaScript Math cos() method example

Here, we will understand cos() method through various examples.

Example 1

Let’s see a simple example of cos() method.

Test it Now

Output:

0.5403023058681398  -0.4161468365471424  

Example 2

In this example, we will use cos() method with negative numbers.

Test it Now

Output:

0.5403023058681398  0.8775825618903728  

Example 3

Let’s see cos() method with some different test cases.

Test it Now

Output:

1  -1  

Example 4

Here, you can test cos() method with your own test cases.

Test it Now

Next TopicJavaScript Math

You may also like