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
Parameter | Optional/Required | Description |
---|---|---|
x | required | A 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,
- We pass the number
1
to theMath.tanh()
method. - The result is approximately
0.7615941559557649
. - 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,
- We pass the number
-1
to theMath.tanh()
method. - The result is approximately
-0.7615941559557649
. - 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,
- We pass the number
0
to theMath.tanh()
method. - The result is
0
. - 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.