Latest web development tutorials
 

JavaScript cos() Method

< JavaScript Math Object

Example

Return the cosine of a number:

Math.cos(3);

The output of the code above will be:

-0.9899924966004454
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: 1.0

Examples

More Examples

Example

Return the cosine PI and 2*PI:

var a = Math.cos(Math.PI);
var b = Math.cos(2 * Math.PI);

The result of a and b will be:

-1
1
Try it Yourself »

< JavaScript Math Object