JavaScript Math.asin() Method



The JavaScript Math.asin() method accepts a number as a parameter and calculates the arcsine (inverse sine) of a number. The result is the angle (in radians) whose sine is the specified number.

If the argument provided to this method is in between -1 and 1 (inclusive), it returns the angle in radians between -PI/2 and PI/2. If the argument is outside the range of -1 or 1 or non-numeric, it returns "NaN (Not a Number)" as result.

Syntax

Following is the syntax of JavaScript Math.asin() method −

 Math.asin(x); 

Parameters

This method accepts only one parameter. The same is described below −

  • x: A numeric value between -1 and 1, representing the sine of an angle.

Return value

This method returns the arcsine (inverse sine) of the provided number in "radians".

Example 1

In this example, we're using the JavaScript Math.asin() method with values between -1 and 1 as arguments −

 <html> <body> <script> let number1 = Math.asin(-1); document.write(number1, "<br>"); let number2 = Math.asin(-0.5); document.write(number2, "<br>"); let number3 = Math.asin(0); document.write(number3, "<br>"); let number4 = Math.asin(0.5); document.write(number4, "<br>"); let number5 = Math.asin(1); document.write(number5); </script> </body> </html> 

Output

It returns the arcsine of the provided arguments.

Example 2

Here, we are passing the out of range values as arguments to this method −

 <html> <body> <script> let number1 = Math.asin(-2); document.write(number1, "<br>"); let number2 = Math.asin(2); document.write(number2); </script> </body> </html> 

Output

We wil get "NaN" as result because both the arguments are not in range -1 to 1.

Example 3

Here, we are passing an argument which is not a numeric value −

 <html> <body> <script> let string = "Tutorialspoint"; let number = Math.asin("Tutorialspoint"); document.write(number); </script> </body> </html> 

Output

If we execute the above program, it returns "NaN" as result.

Advertisements