- Math
- Methods
- Math.abs()
- Math.acos()
- Math.acosh()
- Math.asin()
- Math.asinh()
- Math.atan()
- Math.atan2()
- Math.atanh()
- Math.cbrt()
- Math.ceil()
- Math.cos()
- Math.cosh()
- Math.exp()
- Math.expm1()
- Math.floor()
- Math.fround()
- Math.hypot()
- Math.imul()
- Math.log()
- Math.log10()
- Math.log1p()
- Math.log2()
- Math.max()
- Math.min()
- Math.pow()
- Math.random()
- Math.round()
- Math.sign()
- Math.sin()
- Math.sinh()
- Math.sqrt()
- Math.tan()
- Math.tanh()
- Math.trunc()
- Properties
This is an experimental technology, part of the Harmony (EcmaScript 6) proposal.
Because this technology's specification has not stabilized, check the compatibility table for usage in various browsers. Also note that the syntax and behavior of an experimental technology is subject to change in future version of browsers as the spec changes.
Summary
The Math.tanh() function returns the hyperbolic tangent of a number.
Syntax
Math.tanh(x)
Parameters
-
x - A number.
Description
Because tanh is a static method of Math, you always use it as Math.tanh(), rather than as a method of a Math object you created (Math is not a constructor).
Examples
Example: Using Math.tanh
Math.tanh(0) // 0 Math.tanh(Infinity) // 1 Math.tanh(1) // 0.7615941559557649
Polyfill
This can be emulated with the help of the Math.exp() function:
function tanh(x){
return (Math.exp(x) - Math.exp(-x)) / (Math.exp(x) + Math.exp(-x));
}
Specifications
| Specification | Status | Comment |
|---|---|---|
| ECMAScript Language Specification 6th Edition (ECMA-262) | Draft | Initial definition. |
Browser compatibility
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | Not supported | 25.0 (25) | Not supported | Not supported | Not supported |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | Not supported | Not supported | 25.0 (25) | Not supported | Not supported | Not supported |
Mozilla Developer Network