Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

JavaScript cos() Method

JavaScript cos() Method

Math Object Reference JavaScript Math object

Example

Return the cosine of a number:

Math.cos(3);

The example above produces the following output:

-0.9899924966004454

Try it »


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 value

Parameters Description
x Required. Must be a numeric value.

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

a and b Output result:

-1

1

Try it »


Math Object Reference JavaScript Math object