JavaScript Math.atanh() Method
-
Syntax of JavaScript
Math.atanh()
Method -
Example 1: Use
Math.atanh()
for Values -1 and 1 -
Example 2: Use
Math.atanh()
to Get and Compare the Hyperbolic Arctangent of Numbers -
Example 3: Use
Math.atanh()
With Values Between -1 to 1 -
Example 4: Use
Math.atanh()
for Values Not in Range -1 to 1 -
Example 5: Use
Math.atanh()
With Non-Integer Values
The Math.atanh()
method only takes values between -1 to 1 and returns its inverse hyperbolic tangent. In JavaScript, atanh()
is accessed as a static method of the Math
object.
Syntax of JavaScript Math.atanh()
Method
Math.atanh(x);
Parameters
x |
A number between -1 to 1 is required. |
Return
This method calculates and returns the hyperbolic arctangent of x
if the number is between -1 to 1.
Example 1: Use Math.atanh()
for Values -1 and 1
To calculate the hyperbolic arctangent of a number, we can use the method Math.atanh()
in JavaScript. In this example, we have used the Math.atanh()
method to get the hyperbolic arctangent of the numbers -1 and 1.
Both the numbers give Infinity
or -Infinity
as its hyperbolic arctangent.
let atan = Math.atanh(1);
let atanh = Math.atanh(-1);
console.log(atan);
console.log(atanh);
Output:
Infinity
-Infinity
Example 2: Use Math.atanh()
to Get and Compare the Hyperbolic Arctangent of Numbers
We can get the hyperbolic arctangent of numbers between -1 and 1 on the x-axis. In this example, we have used the Math.atanh()
method to compare the output of two points on the x-axis.
We have taken the 2 numbers with the opposite sign and observed the output in the example below. It gives the same output with the opposite sign.
let atan = Math.atanh(0.3);
let atanh = Math.atanh(-0.3);
console.log(atan);
console.log(atanh);
Output:
0.30951960420311175
-0.30951960420311175
Example 3: Use Math.atanh()
With Values Between -1 to 1
In the example below, we used three values between -1 and 1 to get the output from the Math.atanh()
method. Users can observe the output for different values.
let atan = Math.atanh(0.4);
let atanh = Math.atanh(-0.32);
console.log(atan);
console.log(atanh);
console.log(Math.atanh(0));
Output:
0.42364893019360184
-0.3316471087051321
0
Example 4: Use Math.atanh()
for Values Not in Range -1 to 1
When we pass the parameter values out of range in the Math.atanh()
method, it always returns NaN
values.
In this example, we have used three different values that are not between -1 and 1, and in the output, we got all NaN
values.
let val1 = Math.atanh(1.2);
let val2 = Math.atanh(-1.3);
console.log(val1);
console.log(val2);
console.log(Math.atanh(-12));
Output:
NaN
NaN
NaN
Example 5: Use Math.atanh()
With Non-Integer Values
It is interesting to know the output of the Math.atanh()
method when we pass non-integer values as a method parameter.
In the output of the example below, users can see that the method returns NaN
for the empty string and empty object but returns 0
for the empty array.
let val1 = Math.atanh("Delft");
let val2 = Math.atanh([]);
console.log(val1);
console.log(val2);
console.log(Math.atanh({}));
Output:
NaN
0
NaN
The Math.atanh()
method is supported in all browsers.