JavaScript Math tanh()

The JavaScript Math.tanh() function returns the hyperbolic tangent of a number.

It is equivalent to (ex - e-x)/(ex + e-x) in mathematics.

The syntax of the Math.tanh() function is:

Math.tanh(x)

tanh(), being a static method, is called using the Math class name.


Math.tanh() Parameters

The Math.tanh() function takes in:

  • x - A number

Return value from Math.tanh()

  • Returns the hyperbolic tangent of the given number.

Example: Using Math.tanh()

// Math.tanh(x) is (e**(x) - e**(-x))/(e**(x) + e**(-x))

var num = Math.tanh(0);
console.log(num); // 0

var num = Math.tanh(1);
console.log(num); // 0.7615941559557649

var num = Math.tanh(-1);
console.log(num); // -0.7615941559557649

var num = Math.tanh(2);
console.log(num); // 0.9640275800758169

Output

0
0.7615941559557649
-0.7615941559557649
0.9640275800758169

Recommended readings: