The asin() method calculates the arcsine (inverse of sine) of the specified angle and returns it.
Example
asin() Syntax
The syntax of the Math.asin() method is:
Math.asin(angle)
Here, asin() is a static method. Hence, we are accessing the method using the class name, Math.
asin() Parameter
The asin() method takes a single parameter:
angle- in radians whose arcsine is to be calculated
Note: The value of angle should be between -1 and 1.
asin() Return Value
The asin() method returns:
- arcsine value of the
angle - NaN (Not a Number) if the argument is either non-numeric or greater than 1 or less than -1
Example 1: Math.asin() with argument between -1 and 1
In the above example, the Math.asin() method computes the arcsine of
-1(negative number) - results in -1.57079632679489660.5(positive number) - results in 0.5235987755982989
Example 2 : Math.asin() for other Argument not in the range -1 and 1
Here, we get NaN as output because both the arguments, -100 and 32, are not in the range -1 and 1.
Example 3: Math.asin() with Non-Numeric Argument
In the above example, we have tried to calculate the arcsine of the string "Harry". That's why we get NaN as the output.
Recommended readings: