JavaScript Math cosh() method - JavaScript Tutorial

JavaScript Math cosh() method

BLUF: This tutorial on JavaScript Math cosh() method provides an in-depth look at JavaScript's core features. It includes practical examples and code snippets to help you master modern JS development.
Key Discovery: JavaScript Math cosh() method

Understanding JavaScript Math cosh() method is crucial for building dynamic, interactive web applications. Explore the examples below to see it in action.

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>

Input Required

This code uses input(). Please provide values below:

Logic Practice
Install Logic Practice
Add to home screen for a faster app-like experience