JavaScript Math atanh()

The atanh() method computes the hyperbolic arctangent of the specified value and returns it.

Example

// hyperbolic arctangent of 0.75
let number = Math.atanh(0.75);
console.log(number);
 
// Output: 0.9729550745276566

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

// hyperbolic arctangent of 0 let number1 = Math.atanh(0);
console.log(number1);
// hyperbolic arctangent of 0.5 let number2 = Math.atanh(0.5);
console.log(number2); // Output: // 0 // 0.5493061443340548

In the above example,

  • Math.atanh(0) - computes the hyperbolic arctangent of 0
  • Math.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

// argument greater than 1
let number1 = Math.atanh(2);
console.log(number1);
// argument less than -1
let number2 = Math.atanh(-4);
console.log(number2); // Output: // NaN // NaN

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

// atanh() with argument -1 let number1 = Math.atanh(-1);
console.log(number1);
// atanh() with argument 1 let number2 = Math.atanh(1);
console.log(number2); // Output: // -Infinity // Infinity

The atanh() method returns:

  • Infinity - if the argument is 1
  • -Infinity - if the argument is -1

Example 4: Math.atanh() with Non-Numeric Arguments

let string = "Harry";

// atanh() with string argument let value = Math.atanh(string);
console.log(value); // Output: NaN

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:

Did you find this article helpful?