Javascript - Math cos() Method

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

Description

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

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

Syntax

Math.cos(x)

Parameter Values

Parameter Require Description
x Required. A number

Return

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

Example

Return the cosine of a number:

Demo

//display the cosine value of 3.
console.log(Math.cos(3));//from  w w w  .ja v  a  2  s. c om

//Return the cosine PI and 2*PI:

var a = Math.cos(Math.PI);
var b = Math.cos(2 * Math.PI);
console.log(a + "\n" + b);

Result