cos (JavaScript)

Gets the cosine of an angle.

Defined in

Math (JavaScript)

Syntax

cos(value:double) : double
Parameter Description
value An angle in radians. See below for special cases. See rad (JavaScript) to convert degrees to radians.
Return value Description
double The cosine of the parameter.

Usage

Special cases are as follows:
  • The cosine of NaN or infinity is NaN.

Examples

This button onclick event calculates the two legs of a right triangle given an angle in degrees and the length of the hypotenuse.
sessionScope.a = 
	Math.sin(Math.rad(sessionScope.angleA)) * sessionScope.h;
sessionScope.b = 
	Math.cos(Math.rad(sessionScope.angleA)) * sessionScope.h