JavaScript cos() method

Definition and usage

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

Note:cos() The method returns a number between -1 and 1, representing the cosine value of an angle.

Instance

Example 1

Returns the cosine of a number:

Math.cos(3);

Try it yourself

Example 2

Returns the cosine of PI and 2*PI:

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

Try it yourself

Syntax

Math.cos(x)

Parameter value

Parameter Description
x Required. Number.

Technical details

Return value: The value, ranging from -1 to 1, represents the cosine of an angle. If the value is empty, it returns NaN.
JavaScript Version: ECMAScript 1

Browser Support

Method Chrome Edge Firefox Safari Opera
cos() Support Support Support Support Support

Related Pages

Tutorial:JavaScript Math