Movatterモバイル変換


[0]ホーム

URL:


  1. Web
  2. JavaScript
  3. Reference
  4. Standard built-in objects
  5. Math
  6. tanh()

Math.tanh()

Baseline Widely available

This feature is well established and works across many devices and browser versions. It’s been available across browsers since ⁨July 2015⁩.

TheMath.tanh() static method returns the hyperbolic tangent of a number. That is,

𝙼𝚊𝚝𝚑.𝚝𝚊𝚗𝚑(𝚡)=tanh(x)=sinh(x)cosh(x)=exexex+ex=e2x1e2x+1\mathtt{\operatorname{Math.tanh}(x)} = \tanh(x) = \frac{\sinh(x)}{\cosh(x)} = \frac{\mathrm{e}^x - \mathrm{e}^{-x}}{\mathrm{e}^x + \mathrm{e}^{-x}} = \frac{\mathrm{e}^{2x} - 1}{\mathrm{e}^{2x}+1}

Try it

console.log(Math.tanh(-1));// Expected output: -0.7615941559557649console.log(Math.tanh(0));// Expected output: 0console.log(Math.tanh(Infinity));// Expected output: 1console.log(Math.tanh(1));// Expected output: 0.7615941559557649

Syntax

js
Math.tanh(x)

Parameters

x

A number.

Return value

The hyperbolic tangent ofx.

Description

Becausetanh() is a static method ofMath, you always use it asMath.tanh(), rather than as a method of aMath object you created (Math is not a constructor).

Examples

Using Math.tanh()

js
Math.tanh(-Infinity); // -1Math.tanh(-0); // -0Math.tanh(0); // 0Math.tanh(1); // 0.7615941559557649Math.tanh(Infinity); // 1

Specifications

Specification
ECMAScript® 2026 Language Specification
# sec-math.tanh

Browser compatibility

See also

Help improve MDN

Learn how to contribute

This page was last modified on byMDN contributors.


[8]ページ先頭

©2009-2025 Movatter.jp