JavaScript Math tanh() method

The tanh method in JavaScript computes the hyperbolic tangent of a specified number.

Syntax

The syntax for the tanh function is expressed as follows:

Example

The tanh() method is represented by the following syntax:

Parameter

num - A number.

Return

The hyperbolic tangent of a number.

JavaScript Math tanh method example

In this section, we will explore the tanh function by examining several examples.

Example 1

Let's see a simple example of tanh method.

Example

<script>

document.writeln(Math.tanh(-1)+"<br>");

document.writeln(Math.tanh(0)+"<br>");

document.writeln(Math.tanh(0.5)+"<br>");

document.writeln(Math.tanh(2));

</script>

Output:

Output

-0.7615941559557649

0

0.46211715726000974

0.9640275800758169

Example 2

In this section, you have the opportunity to evaluate the tanh function using your own custom test cases.

Example

<script>

function display()

{

  var x=document.getElementById("num").value;

document.getElementById("result").innerHTML=Math.tanh(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: