totn JavaScript

JavaScript: Math tanh() function

This JavaScript tutorial explains how to use the math function called tanh() with syntax and examples.

Description

In JavaScript, tanh() is a function that is used to return the hyperbolic tangent of a number. Because the tanh() function is a static function of the Math object, it must be invoked through the placeholder object called Math.

Syntax

In JavaScript, the syntax for the tanh() function is:

Math.tanh(number);

Parameters or Arguments

number
The number used to calculate the hyperbolic tangent.

Returns

The tanh() function returns the hyperbolic tangent of a number.

Note

  • Math is a placeholder object that contains mathematical functions and constants of which tanh() is one of these functions.

Example

Let's take a look at an example of how to use the tanh() function in JavaScript.

For example:

console.log(Math.tanh(0.8));
console.log(Math.tanh(1));
console.log(Math.tanh(-5));

In this example, we have invoked the tanh() function using the Math class.

We have written the output of the tanh() function to the web browser console log, for demonstration purposes, to show what the tanh() function returns.

The following will be output to the web browser console log:

0.6640367702678491
0.7615941559557649
-0.9999092042625951

In this example, the first output to the console log returned 0.6640367702678491 which is the hyperbolic tangent of 0.8.

The second output to the console log returned 0.7615941559557649 which is the hyperbolic tangent of 1.

The third output to the console log returned -0.9999092042625951 which is the hyperbolic tangent of -5.