JavaScript Math cosh() Method

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

Visual Representation of JavaScript Math coshExample 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 ValuesVisual Representation of 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 valueVisual Representation of 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

  1. Google Chrome 38 and above
  2. Firefox 25 and above
  3. Opera 25 and above
  4. Safari 8 and above
  5. Edge 12 and above

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.