JavaScript Math tanh() method - JavaScript Tutorial

JavaScript Math tanh() method

BLUF: This tutorial on JavaScript Math tanh() 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 tanh() method

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

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:

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