JavaScript cos()Method

Math 对象参考手册JavaScript Math Object

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

Internet ExplorerFirefoxOperaGoogle ChromeSafari

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);

aandbOutput:

-1
1

Try it Yourself »


Math 对象参考手册JavaScript Math Object

Other Extensions