The cosh method in JavaScript computes the hyperbolic cosine of a specified numerical input.
Syntax
The syntax for the cosh function is expressed as follows:
Example
Math.cosh(num)
Parameter
num - A number.
Return
The hyperbolic cosine of a number.
JavaScript Math cosh method example
In this section, we will explore the cosh function by examining a variety of examples.
Example 1
Let's see a simple example of cosh method.
Example
<script>
document.writeln(Math.cosh(-1)+"<br>");
document.writeln(Math.cosh(0)+"<br>");
document.writeln(Math.cosh(0.5)+"<br>");
document.writeln(Math.cosh(2));
</script>
Output:
Output
1.5430806348152437
1
1.1276259652063807
3.7621956910836314
Example 2
In this section, you have the opportunity to evaluate the cosh function by creating and running your own test scenarios.
Example
<script>
function display()
{
var x=document.getElementById("num").value;
document.getElementById("result").innerHTML=Math.cosh(x);
}
</script>
<form>
Enter a number: <input type="text" id="num">
<input type="button" onclick="display()" value="submit">
</form>
<p><span id="result"></span></p>