Math.cos()
Returns the cosine of an angle given in radians.
Syntax
Math.cos(x) Parameters
| Name | Type | Required | Description |
|---|---|---|---|
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
| Environment | Since version |
|---|---|
| chrome | 1.0 |
| firefox | 1.0 |
| safari | 1.0 |
| edge | 12 |
| node | 0.10 |