JavaScript Math asin() method

The asin function in JavaScript calculates the arcsine of a specified number, providing the result in radians. It is important to note that the input for the asin method must fall within the interval of -1 to 1; if it exceeds this range, the function will return NaN.

Syntax

The syntax for the asin method is expressed as follows:

Example

Math.asin(num)

Parameter

num - A number.

Return

The arcsine of the number.

JavaScript Math asin method example

In this section, we will explore the asin function by examining a variety of examples.

Example 1

Let's see a simple example of asin method.

Example

<script>

document.writeln(Math.asin(-1)+"<br>");

document.writeln(Math.asin(0)+"<br>");

document.writeln(Math.asin(0.5)+"<br>");

document.writeln(Math.asin(1));

</script>

Output:

Output

-1.5707963267948966

0

0.5235987755982989

1.5707963267948966

Example 2

Let's examine scenarios in which the asin function yields NaN.

Example

<script>

document.writeln(Math.asin()+"<br>");

document.writeln(Math.asin(2)+"<br>");

document.writeln(Math.asin(-2));

</script>

Output:

Output

NaN

NaN

NaN

Example 3

In this section, you have the opportunity to evaluate the asin method by creating and utilizing your own test cases.

Example

<script>

function display()

{

  var x=document.getElementById("num").value;

document.getElementById("result").innerHTML=Math.asin(x);

}

</script>

<form>

  Enter a number: <input type="text" id="num">

  <input type="button"  onclick="display()" value="submit">

  </form>

  <p><span id="result"></span></p>

Input Required

This code uses input(). Please provide values below: