Math.cos()

Returns the cosine of an angle given in radians.

Since ES1 Spec ↗

Syntax

Math.cos(x)

Parameters

NameTypeRequiredDescription
x number Yes The angle in radians.

Returns

number — The cosine of x, between -1 and 1.

Examples

console.log(Math.cos(0));
Output
1
console.log(Math.cos(Math.PI));
Output
-1

Notes

The argument is in radians. Floating-point error means `Math.cos(Math.PI / 2)` is a tiny number rather than exactly 0.

Browser & runtime support

EnvironmentSince version
chrome 1.0
firefox 1.0
safari 1.0
edge 12
node 0.10

See also