Tutorial Gateway

  • C Programming
  • Java
  • R
  • SQL
  • MySQL
  • Python
  • BI Tools
    • Informatica
    • Tableau
    • Power BI
    • SSIS
    • SSRS
    • SSAS
    • MDX
    • QlikView
  • About
    • About Us
    • Contact Us

JavaScript TANH

23-11-2015 by suresh Leave a Comment

The JavaScript TANH function is one of the JavaScript Math function which is used to calculate the trigonometry hyperbolic tangent for the specified expression. In this article we will show you, How to use TANH() function in JavaScript Programming language with example.

TIP: Please refer JavaScript TAN Function article to understand the Tangent Function.

Syntax of a JavaScript TANH Function

The basic syntax of the TANH() Function in JavaScript Programming language is as shown below:

1
Math.tanh(number);

Number: It can be a number or a valid numerical expression for which you want to find hyperbolic Tangent value.

  • If the number argument is positive or Negative number, TANH() function will return the hyperbolic Tangent value.
  • If the number argument is not a number, TANH() function will return NaN.
  • If the number argument is null value, TANH() function will return Zero.

HINT: We can achieve the same result using below formula. Please refer JavaScript EXP article to understand the Function.

1
(Math.exp(number) - Math.exp(- number)) / (Math.exp(number) + Math.exp(- number))

JavaScript TANH Function Example

The JavaScript TANH Function allows you to find the trigonometry hyperbolic Tangent for the numeric values. In this example, We are going to find the hyperbolic Tangent values for different data types and display the output

JAVASCRIPT CODE

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<!DOCTYPE html>
<html>
<head>
    <title> JavaScript TANH() Function </title>
</head>
<body>
  <h1> JavaScript TANH Function </h1>
  <p id = "Pos"></p>
  <p id = "Neg"></p>
  <p id = "Dec"></p>
  <p id = "Neg_Dec"></p>
  <p id = "Str"></p>
  <p id = "Exp"></p>
  <p id = "Null"></p>
  <p id = "Multi"></p>
  <script>
    document.getElementById("Pos").innerHTML = Math.tanh(1);
    document.getElementById("Neg").innerHTML = Math.tanh(-2);
    document.getElementById("Dec").innerHTML = Math.tanh(4.45);
    document.getElementById("Neg_Dec").innerHTML = Math.tanh(-2.75);
    document.getElementById("Str").innerHTML = Math.tanh("JavaScript");
    document.getElementById("Null").innerHTML = Math.tanh(null);
    document.getElementById("Multi").innerHTML = Math.tanh(2 + 9 - 7);
  </script>
</body>
</html>

OUTPUT

JavaScript TANH Function

ANALYSIS

Within the First two statements, We used the TANH() Function directly on both the Positive integer and negative integer. Next two statements, We used theTANH() Function on both the Positive and negative Decimal values. If you observe the above screenshot, TANH() function is working perfectly with Integers and Decimal values.

Next, We tried TANH() Function on String value. As we said before, this will return NaN (Not a Number) as output

1
document.getElementById("Str").innerHTML = Math.tanh("JavaScript");

Next, We tried TANH() Function on Null value. As we said before, this will return Zero as output

1
document.getElementById("Null").innerHTML = Math.tanh(null);

In the below statement, We used the TANH() Function directly on multiple values.

1
document.getElementById("Multi").innerHTML = Math.tanh(2 + 9 - 7);

Thank You for Visiting Our Blog

Placed Under: JavaScript

Share your Feedback, or Code!! Cancel reply

Trending

  • SQL Server Integration Services (SSIS)
  • SQL Server Tutorial
  • SQL Server Reporting Services (SSRS)
  • Home
  • C Program to Calculate the Sum and Average of n Number
  • Tableau
  • C Program to Print Prime Numbers from 1 to 100

Stay in Touch!

Sign Up to receive Email updates on Latest Tutorials

  • Blogger
  • C Programs
  • Java Programs
  • SQL
  • SSIS
  • SSRS
  • Tableau
  • JavaScript

Copyright © 2018 | Tutorial Gateway· All Rights Reserved by Suresh

Home | About Us | Contact Us | Privacy Policy