JavaScript Math cosh() Method

JavaScript Math cosh() method is “used to return the hyperbolic cosine of a number”.

Syntax

Math.cosh(x)

Parameters

x: It is the variable x, whose hyperbolic cosine value will be determined.

Return Value

The hyperbolic cosine value.

See the following figure.

 

JavaScript Math cosh()

Note:

If the passed value is not a valid number, the method returns NaN.

Example 1

var a = 1;
var b = -1;
var c = 0;
var d = 4;
var e = -2;
var f = 2;

console.log(Math.cosh(a));
console.log(Math.cosh(b));
console.log(Math.cosh(c));
console.log(Math.cosh(d));
console.log(Math.cosh(e));
console.log(Math.cosh(f));

Output

1.5430806348152437
1.5430806348152437
1
27.308232836016487
3.7621956910836314
3.7621956910836314

Example 2

The following example illustrates cases where values other than valid numbers are passed.

var a = "Hello, world";
var b;

console.log(Math.cosh(a));
console.log(Math.cosh(b));

Output

NaN
NaN

Example 3

The cosh() method cannot be used with complex arguments as only integer arguments are accepted.

console.log(Math.cosh(2 + i));

Output

ReferenceError: i is not defined 

Conclusion

To find a given number’s hyperbolic cosine value, you can use the math.cosh() function.

That’s it.

Leave a Comment

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