How to Use the Math.asin() Method in JavaScript

09/30/2021

Contents

In this article, you will learn how to use the Math.asin() method in JavaScript.

Using the Math.asin() method in JavaScript

The Math.asin() method is a built-in function in JavaScript that returns the arcsine (in radians) of a given number. The input parameter must be a value between -1 and 1. If the parameter is outside of this range, the method will return NaN (not a number).

Syntax

The syntax for using the Math.asin() method is:

Math.asin(x)

where x is the input parameter that represents the sine of an angle.

Examples

Using Math.asin() to calculate the arcsine of a number

const x = 0.5;
const arcsine = Math.asin(x);
console.log(arcsine); // 0.5235987755982989

In this example, the input parameter is 0.5, which represents the sine of an angle. The output is the arcsine of 0.5 in radians, which is approximately 0.5236.

Using Math.asin() with a value outside the range of -1 to 1

const x = 2;
const arcsine = Math.asin(x);
console.log(arcsine); // NaN

In this example, the input parameter is 2, which is outside the range of -1 to 1. Therefore, the output is NaN.

Using Math.asin() with a negative value

const x = -0.7;
const arcsine = Math.asin(x);
console.log(arcsine); // -0.775397496610753

In this example, the input parameter is -0.7, which represents the sine of an angle. The output is the arcsine of -0.7 in radians, which is approximately -0.7754.

Note: The output of the Math.asin() method is always in radians. If you want to convert the result to degrees, you can use the following formula:

degrees = radians * (180 / Math.PI)

where radians is the output of the Math.asin() method.