JavaScript Math.tanh()
Syntax & Examples


Math.tanh() static-method

The Math.tanh() static method in JavaScript returns the hyperbolic tangent of a number. The number is assumed to be in radians.


Syntax of Math.tanh()

The syntax of Math.tanh() static-method is:

Math.tanh(x)

This tanh() static-method of Math returns the hyperbolic tangent of the given number x, where x is in radians.

Parameters

ParameterOptional/RequiredDescription
xrequiredA number representing an angle in radians whose hyperbolic tangent is to be calculated.

Return Type

Math.tanh() returns value of type Number.



✐ Examples

1 Using Math.tanh() with a positive number

In JavaScript, we can use the Math.tanh() method to calculate the hyperbolic tangent of a positive number.

For example,

  1. We pass the number 1 to the Math.tanh() method.
  2. The result is approximately 0.7615941559557649.
  3. We log the result to the console using the console.log() method.

JavaScript Program

const result = Math.tanh(1);
console.log(result);

Output

0.7615941559557649

2 Using Math.tanh() with a negative number

In JavaScript, we can use the Math.tanh() method to calculate the hyperbolic tangent of a negative number.

For example,

  1. We pass the number -1 to the Math.tanh() method.
  2. The result is approximately -0.7615941559557649.
  3. We log the result to the console using the console.log() method.

JavaScript Program

const result = Math.tanh(-1);
console.log(result);

Output

-0.7615941559557649

3 Using Math.tanh() with zero

In JavaScript, we can use the Math.tanh() method to calculate the hyperbolic tangent of zero.

For example,

  1. We pass the number 0 to the Math.tanh() method.
  2. The result is 0.
  3. We log the result to the console using the console.log() method.

JavaScript Program

const result = Math.tanh(0);
console.log(result);

Output

0

Summary

In this JavaScript tutorial, we learned about tanh() static-method of Math: the syntax and few working examples with output and detailed explanation for each example.