JavaScript Math cosh() method is used to calculate the hyperbolic cosine of a number.
Syntax
Math.cosh(num)
Parameters
num(required): It is the number whose hyperbolic cosine value will be determined.
Return Value
Returns the hyperbolic cosine of a number.
If the passed value is non-numeric or empty, the method returns NaN.
Visual Representation
Example 1: How to Use Math cosh() Method
let a = 1; //positive number
let b = -1; //negative number
let c = 2.4; //float number
let d = 0;
console.log(Math.cosh(a));
console.log(Math.cosh(b));
console.log(Math.cosh(c));
console.log(Math.cosh(d));
Output
1.5430806348152437
1.5430806348152437
5.556947166965507
1
Example 2: Passing Infinity Values
console.log(Math.cosh(Infinity)); //positive value
console.log(Math.cosh(-Infinity)); //negative value
Output
Infinity
Infinity
Example 3: Handling Non-numeric and empty value
console.log(Math.cosh("Messi")); //non-numeric value
console.log(Math.cosh()); //empty value
Output
NaN
NaN
Browser Compatibility
- Google Chrome 38 and above
- Firefox 25 and above
- Opera 25 and above
- Safari 8 and above
- Edge 12 and above
Ankit Lathiya is a Master of Computer Application by education and Android and Laravel Developer by profession and one of the authors of this blog. He is also expert in JavaScript and Python development.