Favorites

JavaScript Math.cos() Method

☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee
Math.cos()
JavaScript Math Static methodThis method is supported by all modern browsers.
Updated 28th November 2026

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

console.log(Math.cos(0));
console.log(Math.cos(Math.PI));
const angle = 60 * Math.PI / 180;
console.log(Math.cos(angle).toFixed(3));

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.

This method is supported by all modern browsers.

Desktop

Chrome
Edge
Firefox
Opera
Safari

Tablets & Mobile

Chrome Android
Firefox Android
Opera Android
Safari iOS
Samsung Internet
Android WebView
-
Supported Unknown Not supported
☕
Enjoying this site?

Help keep it running with a small coffee donation. Every bit of support is appreciated!

Buy us a coffee