X
HOME HTML CSS JAVASCRIPT SQL PHP JQUERY ANGULAR BOOTSTRAP XML ASP.NET MORE...
REFERENCES | EXAMPLES | FORUM | ABOUT

JavaScript cos() Method

Math Object Reference JavaScript Math Object

Example

Return the cosine of a number:

Math.cos(3);

The output of the code above will be:

-0.9899924966004454

Try it yourself »

More "Try it Yourself" examples below.


Definition and Usage

The cos() method returns the cosine of a number.

Note: The cos() method returns a numeric value between -1 and 1, which represents the cosine of the angle.


Browser Support

Method
cos() Yes Yes Yes Yes Yes


Syntax

Math.cos(x)

Parameter Values

Parameter Description
x Required. A number

Technical Details

Return Value: A Number, from -1 to 1, representing the cosine of an angle, or NaN if the value is empty
JavaScript Version: 1.0


Examples

More Examples

Example

Return the cosine PI and 2*PI:

var a = Math.cos(Math.PI);
var b = Math.cos(2 * Math.PI);

The result of a and b will be:

-1
1

Try it yourself »


Math Object Reference JavaScript Math Object

Your suggestion:

Close [X]

Thank You For Helping Us!

Your message has been sent to W3Schools.

Close [X]
Search w3schools.com:

WEB HOSTING

UK Reseller Hosting

WEB BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE

facebook