Home »
JavaScript
Math.tanh() Method with Example in JavaScript
JavaScript | Math.tanh() Method: Here, we are going to learn about the tanh() method of Math class in JavaScript with Examples.
Submitted by Shivang Yadav, on December 21, 2019
JavaScript | Math.tanh() Method
Math.tanh() is a function in math library of JavaScript that is used to find the value of hyperbolic tangent of a number.
Calculation of mathematical Formula:
tanh(p) = sin(p) / cos(p) = ep - e-p / ep + e-p
Where e is the mathematical constant with value 2.718
Syntax:
Math.tanh(p);
Parameter(s):
- p – It represents the value whose hyperbolic tangent value to be found.
Return value:
The return type of this method is number, it returns the hyperbolic tangent value of the given p.
Example 1: Find the tanh of numeric values
console.log(Math.tanh(0));
console.log(Math.tanh(7));
console.log(Math.tanh(-5));
console.log(Math.tanh(4.52));
Output
0
0.9999983369439447
-0.9999092042625951
0.9997628864418443
Example 2: Find the tanh of non-numeric values
console.log(Math.tanh("IncludeHelp"));
// Output: NaN
console.log(Math.tanh(3 + 5i));
// Output: Uncaught SyntaxError: Invalid or unexpected token
JavaScript Math Object Methods »