How to use cos in JavaScript

In this article, I will explain use of cos() method in JavaScript.
  • 2311

JavaScript cos() Method

  • cos() method of math object returns the cosine of a number.

  • cos() method returns a numeric value between -1 and 1.

  • In cos() method, numeric value represents the cosine of the angle.

Syntax

Math.cos(x)

  • x is a Required number

Example

In the following example show to cos() method returns the cosine of numbers.

<html>

<head>

</head>

<body>

<h3 style="color:Blue">JavaScript cos() Method Example</h3>

<script type="text/javascript">

    var a = Math.cos(30);

    document.write("First Test cos Value : " + a);

    var b = Math.cos(60);

    document.write("<br />Second Test cos Value : " + b);

    var c = Math.cos(-1);

    document.write("<br />Third Test cos Value : " + c);

    var d = Math.cos(2 * Math.PI);

    document.write("<br />Fourth Test cos Value : " + d);

</script>

</body>

</html>

Output

cos.jpg

You may also want to read these related articles here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.