The cosh() method computes the hyperbolic cosine of the specified number and returns it.
Example
cosh() Syntax
The syntax of the Math.cosh() method is:
Math.cosh(number)
Here, cosh() is a static method. Hence, we are accessing the method using the class name, Math.
cosh() Parameter
The cosh() method takes a single parameter:
number- whose hyperbolic cosine is to be calculated
cosh() Return Value
The cosh() method returns:
- hyperbolic cosine of the given argument
number - NaN (Not a Number) for a non-numeric argument
Example1: JavaScript Math.cosh()
In the above example, the Math.cosh() method computes the hyperbolic cosine of
-1(negative number) - results in 1.54308063481524370(zero) - results in 12(positive number) - results in 3.7621956910836314
Note: Mathematically, the hyperbolic cosine is equivalent to (ex + e-x)/2.
Example 2: Math.cosh() with Infinity Values
Example 3: Math.cosh() with Non-Numeric Argument
In the above example, we have tried to calculate the hyperbolic cosine value of the string "Harry". That's why we get NaN as the output.
Recommended readings: