cos

Returns the cosine of a number.

Applies to

Math

Syntax

cos(x)

Parameters

x

A number.

Description

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

cos is a static method of Math. As a result, you always use it as Math.cos(), rather than as a method of a Math object you create.

Examples

The following function returns the cosine of the variable x:

function getCos(x) {
      return Math.cos(x)
}

If x equals Math.PI/2, getCos returns 6.123031769111886e-017; if x equals Math.PI, getCos returns -1.

See also

Math:acos, Math.asin, Math.atan, Math.atan2, Math.sin, Math.tan