JavaScript cos()Method
Example
Return the cosine of a number:
Math.cos(3);
The output of the above example is:
-0.9899924966004454
Try it Yourself »
Definition and Usage
The cos() method returns the cosine of a number.
Note:cos() returns a number between -1.0 and 1.0.
Browser Support
![]()
![]()
![]()
![]()
![]()
All major browsers support the cos() method.
Syntax
Math.cos(x)
Parameter Values
| Parameter | Description |
|---|---|
| x | Required. Must be a number. |
Return Value
| Type | Description |
|---|---|
| Number | The cosine of x. Returns a number between -1.0 and 1.0. |
Technical Details
| JavaScript Version: | 1.0 |
|---|
More Examples
Example
Return the cosine of PI and 2*PI:
var a=Math.cos(Math.PI);
var b=Math.cos(2*Math.PI);
var b=Math.cos(2*Math.PI);
aandbOutput:
-1
1
1
Try it Yourself »
Other Extensions
JavaScript Math Object