JavaScript Math.cos() Method
The Math.cos() static method returns the cosine of an angle given in radians.
Description
The Math.cos() static method returns the cosine of an angle, which must be in radians. Together with Math.sin(), it's used to place things on a circle: x = cx + r * Math.cos(angle). Convert degrees with deg * Math.PI / 180.
Because angles are in radians, Math.cos(90) means 90 radians, not 90 degrees, which is a common mistake. Floating point precision also means Math.cos(Math.PI / 2) returns a tiny number like 6e-17 rather than exactly 0, so round results before comparing them.
Common uses include drawing on a canvas, positioning items around a circle, and creating smooth back-and-forth motion in animations. Like every member of Math, it's called on the Math object itself rather than on a number, and it only works with the Number type: passing a BigInt throws a TypeError.
Syntax
Math.cos(x)Parameters
- xAn angle in radians.
Return Value
The cosine of the angle, from -1 to 1.
Example
Browser Support
The following information will show you the current browser support for the Math.cos() method. Hover over a browser icon to see the version that first introduced support for this method.
Desktop





Tablets & Mobile





