Introduction JavaScript Math Cosh() Function with Examples

Math operations in JavaScript are handled using functions of math library in JavaScript. In this tutorial on Math.cosh() method, we will learn about the cosh() method and its working with examples.

Math.cosh() is a function in math library of JavaScript that is used to find the value of hyperbolic cosine of a number.

Syntax:

Math.cosh(x)

Parameter(s):

  • x – It represents the value whose hyperbolic cosine value to be found.

Return value:

The return type of this method is number, it returns the hyperbolic cosine value of the given p.

JavaScript Math Cosh () Example

Example 1:

See the following code example.

//example1.js

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

node example1
1.5430806348152437
1.5430806348152437
1
27.308232836016487
3.7621956910836314
3.7621956910836314

Example 2:

The following example demonstrates the case where values other than valid numbers are passed.


// example2.js

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

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

Output

node example2
NaN
NaN

If you want to find the hyperbolic cosine value of a given number, then you can use the Javascript math.cosh() function.

Thanks for reading !

#javascript #js #web-developer

Introduction JavaScript Math Cosh() Function with Examples
1 Likes14.35 GEEK