Function Updated 16 May 2026
Math.cos(angle)
Returns the cosine of a number in radians. The returned value is between -1 and 1.
Parameters
anglenumberrequiredA number representing an angle in radians.
Returns
A number between -1 and 1, representing the cosine of the given angle (in radians).
Example
Normal JavaScript, 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
*/The JavaScript above produces this output:
1
-1
-1