The cosh()
method computes the hyperbolic cosine of the specified number and returns it.
Example
// hyperbolic cosine of 1
let number = Math.cosh(1);
console.log(number);
// Output: 1.5430806348152437
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()
// hyperbolic cosine of negative number
let number1 = Math.cosh(-1);
console.log(number1);
// hyperbolic cosine of zero
let number2 = Math.cosh(0);
console.log(number2);
// hyperbolic cosine of positive number
let number3 = Math.cosh(2);
console.log(number3);
// Output:
// 1.5430806348152437
// 1
// 3.7621956910836314
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
// cosh() with positive infinity
let number1 = Math.cosh(Infinity);
console.log(number1);
// Output: Infinity
// cosh() with negative infinity
let number2 = Math.cosh(-Infinity);
console.log(number2);
// Output: Infinity
Example 3: Math.cosh() with Non-Numeric Argument
let string = "Harry";
// cosh() with a string argument
let value = Math.cosh(string);
console.log(value);
// Output: NaN
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.
Also Read: