cos()  Math  class methodS2C Home  « Globals « Math « cos()

Description

Returns the cosine of a number in radians.

  • Radians to Degrees - divide number by (Math.PI / 180).
  • Degrees to Radians - multiply number by (Math.PI * 180).
  • Like all class methods cos() should be used on the class rather than an instance of the class.

Syntax

Signature Description
Math.cos(value)Returns the cosine of a number in radians.

Parameters

Parameter Description
valueThe number you wish to find the cosine in radians for:
  • Non-numeric strings returns NaN.
  • Passing no parameter returns NaN.
  • Passing null returns 1.

Examples

The code below displays cos() usage.


/*
 * Store results in an array.
 */ 
var cosValues = new Array(5);
cosValues[0] = Math.cos(-1);
cosValues[1] = Math.cos(0);
cosValues[2] = Math.cos('0.75');
cosValues[3] = Math.cos('a string');
cosValues[4] = Math.cos();
cosValues[5] = Math.cos(null);
alert(cosValues);  

Press the button below to action the above code:


Related Tutorials

JavaScript Advanced Tutorials - Lesson 4 - Math

go to home page Homepage go to top of page Top