HomeLanguagesJavascriptJavaScript Math cos() Method

JavaScript Math cos() Method

The Javascript Math.cos() method 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 a single parameter as mentioned above and described below: 

  • Value: This parameter is a number given in radians.

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

Below is an example of the Math cos() Method. 

Example: This example returns the cosine of 0.

Javascript




console.log("The cos of 0 : " + Math.cos(0));


Output

The cos of 0 : 1

Example 1: This example returns the cosine of 010.

Javascript




console.log("Result : " + Math.cos(010));


Output

Result : -0.14550003380861354

Example 2: When 1 is passed as a parameter.

Javascript




console.log("Result : " + Math.cos(1));


Output

Result : 0.5403023058681398

Example 3: When PI is passed as a parameter.  

Javascript




console.log("Result : " + Math.cos(Math.PI));


Output

Result : -1

Example 4: When Input is in degrees (not in radians)

Javascript




const degree = 90;
console.log(
"cos(" + degree + ") = " + Math.cos((Math.PI * degree) / 180));


Output

cos(90) = 6.123233995736766e-17

We have a complete list of Javascript Math Objects methods, to check those please go through this Javascript Math Object Complete reference article.

RELATED ARTICLES

Most Popular

Dominic
32662 POSTS0 COMMENTS
Milvus
131 POSTS0 COMMENTS
Nango Kala
7037 POSTS0 COMMENTS
Nicole Veronica
12174 POSTS0 COMMENTS
Nokonwaba Nkukhwana
12263 POSTS0 COMMENTS
Shaida Kate Naidoo
7161 POSTS0 COMMENTS
Ted Musemwa
7428 POSTS0 COMMENTS
Thapelo Manthata
7128 POSTS0 COMMENTS
Umr Jansen
7127 POSTS0 COMMENTS