JavaScript Tutorial JavaScript Resources
Python Java C++ C C# PHP R SQL DS Algo InterviewQ

JavaScript - Math.cos() Method

The JavaScript Math.cos() method returns trigonometric cosine of an angle (angle should be in radians). In the graph below, cos(x) vs x is plotted.

Cos Function




x Specify the angle in radian.

Return Value

Returns the trigonometric cosine of an angle.


In the example below, Math.cos() method is used to find out the trigonometric cosine of an angle.

//Math.PI - value of PI from Math object
var pi = Math.PI;
var txt;

txt = "Math.cos(pi/6) = " + Math.cos(pi/6) + "<br>";
txt = txt + "Math.cos(pi/4) = " + Math.cos(pi/4) + "<br>";
txt = txt + "Math.cos(pi/3) = " + Math.cos(pi/3) + "<br>";

The output (value of txt) after running above script will be:

Math.cos(pi/6) = 0.8660254037844387
Math.cos(pi/4) = 0.7071067811865476
Math.cos(pi/3) = 0.5000000000000001

❮ JavaScript - Math Object