The atanh() method computes the hyperbolic arctangent of the specified value and returns it.
Example
atanh() Syntax
The syntax of the Math.atanh() method is:
Math.atanh(number)
Here, atanh() is a static method. Hence, we are accessing the method using the class name, Math.
atanh() Parameter
The atanh() method takes a single parameter:
number- between -1 and 1 whose hyperbolic arctangent is to be calculated
Math.atanh() Return Value
The atanh() method returns:
- hyperbolic arctangent of the argument
number - NaN (Not a Number) if the argument is either non-numeric or greater than 1 or less than -1
Example 1: JavaScript Math.atanh() with argument between -1 and 1
In the above example,
Math.atanh(0)- computes the hyperbolic arctangent of 0Math.atanh(0.5)- computes the hyperbolic arctangent of 0.5
Note: Hyperbolic arctangent i.e, atanh(number) is a unique number 'x' in the range [-1, 1] such that tanh(x) = number.
Example 2: Math.atanh() for Argument not in the Range -1 to 1
The atanh() method returns NaN because both the arguments 2 and -4 are not in the range -1 and 1.
Example 3: Math.atanh() for Arguments -1 and 1
The atanh() method returns:
- Infinity - if the argument is 1
- -Infinity - if the argument is -1
Example 4: Math.atanh() with Non-Numeric Arguments
In the above example, we have tried to calculate the hyperbolic arctangent of the string "Harry". Hence, we get NaN as the output.
Recommended readings: