JavaScript cos() Method
THE WORLD'S LARGEST WEB DEVELOPER SITE

JavaScript cos() Method

❮ JavaScript Math Object

Example

Return the cosine of a number:

Math.cos(3);
Try it Yourself »

More "Try it Yourself" examples below.


Definition and Usage

The cos() method returns the cosine of a number.

Note: The cos() method returns a numeric value between -1 and 1, which represents the cosine of the angle.


Browser Support

Method
cos() Yes Yes Yes Yes Yes

Syntax

Math.cos(x)

Parameter Values

Parameter Description
x Required. A number


Technical Details

Return Value: A Number, from -1 to 1, representing the cosine of an angle, or NaN if the value is empty
JavaScript Version: ECMAScript 1

More Examples

Example

Return the cosine PI and 2*PI:

var a = Math.cos(Math.PI);
var b = Math.cos(2 * Math.PI);
Try it Yourself »

❮ JavaScript Math Object