HOME HTML CSS JAVASCRIPT SQL PHP JQUERY 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 »

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

Internet Explorer Firefox Opera Google Chrome Safari

The cos() method is supported in all major browsers.


Syntax

Math.cos(x)

Parameter Values

Parameter Description
x Required. A number

Return Value

Type Description
Number A Number, from -1 to 1, representing the cosine of an angle, or NaN if the value is empty

Technical Details

JavaScript Version: 1.0


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 BUILDING

Download XML Editor FREE Website BUILDER Free HTML5 Templates

SHARE THIS PAGE