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.
Math.cosh(x)
The return type of this method is number, it returns the hyperbolic cosine value of the given p.
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
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