Math.cos(angle) Last updated: 16. May 2026

Returns the cosine of a number in radians. The returned value is between -1 and 1.

See also: Math.sin Math.tan Math.atan

Parameters

Name Type Description
angle number A number representing an angle in radians.

Returns

A number between -1 and 1, representing the cosine of the given angle (in radians).

Example

Code example (JS)

JS is normal JavaScript either running in the browser or on the Docly™ server.
function getCosFromDegrees(degrees) {
  return Math.cos(degrees * Math.PI / 180);
}

write(Math.cos(0));
write("\n");
write(Math.cos(Math.PI));
write("\n");
write(getCosFromDegrees(180));
/* Expected output:
1
-1
-1
*/

Output

The JS code above produces the output shown below:
1
-1
-1