Categories
JavaScript Web development

JavaScript cos() & cosh() Methods

JavaScript cos() & cosh() Methods

The JavaScript Math.cos() returns the cosine of a number.

The JavaScript Math.cos() returns a numeric value between -1 and 1, that represents the cosine of the angle.

Syntax:

Math.cos(x)

Example:

<!DOCTYPE html>
<html>
<body>

<p id="example"></p>

<script>
function cosFunction() {
  document.getElementById("example").innerHTML = Math.cos(2);
}
</script>

</body>
</html>

Output:

Click the button to display the cosine value of 2:


The JavaScript Math.cosh() returns the hyperbolic cosine of a number.

Syntax:

Math.cosh(x)

Example:

<!DOCTYPE html>
<html>
<body>

<button onclick="coshFunction()">Try it</button>

<p id="example1"></p>

<script>
function coshFunction() {
  document.getElementById("example1").innerHTML = Math.cosh(2);
}
</script>

</body>
</html>

Output:

Click the button to display the hyperbolic cosine value of 2.


Enjoy coding!

Read also:

JavaScript Math Object

JavaScript random() Method

JavaScript atan(), atan2() & atanh() Methods