JavaScript: Math atanh() function
This JavaScript tutorial explains how to use the math function called atanh() with syntax and examples.
Description
In JavaScript, atanh() is a function that is used to return the hyperbolic arc tangent (also called inverse hyperbolic tangent) of a number. Because the atanh() 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 atanh() function is:
Math.atanh(number);
Parameters or Arguments
- number
- The number used to calculate the hyperbolic arc tangent. The number must be less than 1 and greater than -1.
Returns
The atanh() function returns the hyperbolic arc tangent of a number.
If the number is 1, the atanh() function will return Infinity.
If the number is -1, the atanh() function will return -Infinity.
If the number is greater than 1 or the number is less than -1, the atanh() function will return NaN.
Note
- Math is a placeholder object that contains mathematical functions and constants of which atanh() is one of these functions.
Example
Let's take a look at an example of how to use the atanh() function in JavaScript.
For example:
console.log(Math.atanh(0.8));
console.log(Math.atanh(1));
console.log(Math.atanh(-1));
console.log(Math.atanh(2));
console.log(Math.atanh(-2));
In this example, we have invoked the atanh() function using the Math class.
We have written the output of the atanh() function to the web browser console log, for demonstration purposes, to show what the atanh() function returns.
The following will be output to the web browser console log:
1.0986122886681098 Infinity -Infinity NaN NaN
In this example, the first output to the console log returned 1.0986122886681098 which is the hyperbolic arc tangent of 0.8.
The second output to the console log returned Infinity because the number provided was 1.
The third output to the console log returned -Infinity because the number provided was -1.
The fourth and fifth output to the console log returned NaN because the number provided was greater than 1 or less than -1.
Advertisements