JavaScript Math.cosh() Method



The JavaScript Math.cosh() method is accepts a numeric value as a parameter and returns the hyperbolic cosine of that number. If we provide a non-numeric value or empty number, it returns NaN as result.

cosh(x) = (e^x + e^(-x)) / 2

Where e is Euler's number, approximately equal to 2.71828, and x is the input value.

Note − This method is not supported in Interner Explorer.

Syntax

Following is the syntax of JavaScript Math.cosh() method −

Math.cosh(x);

Parameters

This method accepts only one parameter. The same is described below −

  • x: A numeric value.

Return value

This method returns the hyperbolic cosine of the provided number.

Example 1

In the following example, we are demonstating the basic usage of JavaScript Math.cosh() method −

<html>
<body>
<script>
   let number1 = Math.cosh(-1);
   document.write(number1, "<br>");

   let number2 = Math.cosh(0);
   document.write(number2, "<br>");

   let number3 = Math.cosh(1);
   document.write(number3);
</script>
</body>
</html>

Output

The above program returns the hyperbolic cosine of the provided numbers.

Example 2

Here, we are using the Math.cosh() method with Infinity values −

<html>
<body>
<script>
   let number1 = Math.cosh(Infinity);
   document.write(number1, "<br>");

   let number2 = Math.cosh(-Infinity);
   document.write(number2);
</script>
</body>
</html>

Output

If we execute the above program, it returns Infinity as result.

Example 3

If we try to calculate the hyperbolic cosine value of a non-numeric value or empty number, it returns NaN as result −

<html>
<body>
<script>
   let number1 = Math.cosh("Tutorialspoint");
   document.write(number1, "<br>");

   let number2 = Math.cosh();
   document.write(number2);
</script>
</body>
</html>

Output

As we can see in the output, the above program returned NaN.