# How to get the arcsine (in radians) of a number in JavaScript?

Sine is the ratio of the opposite side and hypotenuse of the right triangle they define.

To get the sine of a number, the Math.sin() function is used in JavaScript. It returns a value between 1 and -1. This represents the sine of an angle. This will be in radians.

The inverse of sine is called Arc sine. An angle's trigonometric Arc sine value can be calculated using asin() method. This returns a value between -π/2 and π/2.

The input to asin() method is one argument 1 ≥ n ≥ -1. And the function returns arc sine value in radians. The Mathematical representation is as follows asin(x) = sine1(x)=1/sine(x). Next, we will see the method to find arcsine in JavaScript.

Next, we will see the method to find arcsine in JavaScript.

## Using the Math.asin() Method

Here, we will learn about the Math.asin() method in JavaScript. This method returns the arc sine value of a number in JavaScript. The value returned is if the number is between -1 and 1. If the number is outside this range, this method returns NaN. This is an ECMAScript1(ES1) feature.

Google Chrome 1 and above, internet explorer 3 and above, Firefox 1 and above, Opera 3 and above and Safari 1, and above are the supported browsers.

### Syntax

Math.asin(number);


Here, the number value must be between 1 and -1.

### Parameters

• number − This is the number for which the arcsine value in radians has to be found.

### Example 1

In this example, two <p> tags are created to display the output. Values between 1 and -1 are assigned to the first set of variables for getting the arcsine value correctly. Values such as a string and values from the range between 1 and -1 are assigned to the second set of variables. Math.asin() method executes all the inputs, and the output is displayed.

<html>
<body>
<h4> Finding the arcsine of a number in JavaScript using <i> Math.asin()
</i></h4>
<p id = "asinDisp1"> </p>
<p id = "asinDisp2"> </p>
<script>
let x1 = Math.asin(0.63);
let x2 = Math.asin(-0.8);
let x3 = Math.asin(-1);
let x4 = Math.asin(0);
let x5 = Math.asin(0.6);
let x6 = Math.asin(1);
let x7 = Math.asin(Math.PI/10);
let y1 = Math.asin(-3);
let y2 = Math.asin(3);
let y3 = Math.asin("Best");
let y4 = Math.asin(Math.PI/2);
var asinDispEl1 = document.getElementById("asinDisp1");
asinDispEl1.innerHTML = "Math.asin(0.63) = " + x1 + "<br>" + "Math.asin(-0.8) = " + x2 + "<br>" + "Math.asin(-1) = " + x3 + "<br>" +"Math.asin(0) = " + x4 + "<br>" + "Math.asin(0.6) = " + x5 + "<br>" +"Math.asin(1) = " + x6 + "<br>" + "Math.asin(Math.PI/10) = " + x7 +"<br>";
var asinDispEl2 = document.getElementById("asinDisp2");
asinDispEl2.innerHTML = "Math.asin(-3) = " + y1 + "<br>" + "Math.asin(3)= " + y2 + "<br>" + "Math.asin('Best') = " + y3 + "<br>"+"Math.asin(Math.PI/2) = " + y4 + "<br>";
</script>
</body>
</html>


### Example 2

In this example, a p tag is created to display the output. Here, the input is given to Math.asin() like 2+1, 1-1, 0.2+0.2. This is the same as a mathematical operation. Based on the range of the result, the arcsine value is returned. That is 2+1=3 out of 1 and -1, which returns NaN. 1-1=0, which is within the range ,and the output is returned.

<html>
<body>
<h4> Finding the arcsine value of a number using <i> Math.asin() </i>
Math operation example</h4>
<p id = "asinNumOut"> </p>
<script>
var asinNumOutEl = document.getElementById("asinNumOut");
asinNumOutEl.innerHTML = "Math.asin(2+2) = " + Math.asin(2+2) + "<br>" +"Math.asin(02+0.2) = " + Math.asin(02+0.2) + "<br>" + "Math.asin(1-1) = " + Math.asin(1-1);
</script>
</body>
</html>


This tutorial helped us to learn about the Math.asin() method in JavaScript. This method finds the arcsine value of a number in radians. The method returns the value if the input given is between 1 and -1. Else it returns NaN. We have also given some operations along with the input like 2+1. For any input that we gave, the method returned the value according to the input.

Updated on: 31-Oct-2022

133 Views 